leap-lyhour/lighthouse-graphql-sanctum-auth
Composer 安装命令:
composer require leap-lyhour/lighthouse-graphql-sanctum-auth
包简介
Enterprise-grade Laravel Package for Lighthouse GraphQL with Sanctum Authentication, Spatie Permissions, Multi-Tenancy, 2FA, and Audit Logging
关键字:
README 文档
README
Enterprise-grade Laravel Package that provides Laravel Sanctum Authentication with Lighthouse GraphQL, Spatie Laravel Permission, Multi-Tenant Support, 2FA, Refresh Token System, Device Management, Audit Logging, IP Filtering, Ownership & Row-Level Security.
Laravel Package Enterprise-grade ដែលផ្តល់ Laravel Sanctum Authentication ជាមួយ Lighthouse GraphQL, Spatie Laravel Permission, Multi-Tenant Support, 2FA, Refresh Token System, Device Management, Audit Logging, IP Filtering, Ownership & Row-Level Security។
Features / Features
- ✅ Laravel Sanctum Authentication (SPA + Token) / Authentication Sanctum (SPA + Token)
- ✅ Lighthouse GraphQL (Queries, Mutations, Directives) / Lighthouse GraphQL (Queries, Mutations, Directives)
- ✅ Spatie Laravel Permission (Roles & Permissions) / Spatie Permission (Roles & Permissions)
- ✅ Multi-Tenant Support (Single DB + Multi DB) / ការគាំទ្រ Multi-Tenant (Single DB + Multi DB)
- ✅ 2FA (Google Authenticator) / 2FA (Google Authenticator) - Planned / គ្រោង
- ✅ Refresh Token System / ប្រព័ន្ធ Refresh Token
- ✅ Device Management / ការគ្រប់គ្រង Device
- ✅ Audit Logging System / ប្រព័ន្ធ Audit Logging
- ✅ IP Filtering / ការច្រោះ IP - Planned / គ្រោង
- ✅ Ownership & Row-Level Security / Ownership & Row-Level Security
- ✅ Tenant Resolver (Domain, Header, Token) / Tenant Resolver (Domain, Header, Token)
- ✅ Enterprise Directives / Directives Enterprise:
@hasRole- Role-based access control / ការគ្រប់គ្រងការចូលប្រើប្រាស់ផ្អែកលើ role@hasPermission- Permission-based access control / ការគ្រប់គ្រងការចូលប្រើប្រាស់ផ្អែកលើ permission@ownership- Resource ownership verification / ការផ្ទៀងផ្ទាត់ ownership resource@belongsToTenant- Multi-tenant isolation / ការញែក multi-tenant@audit- Audit logging / Audit logging
Installation / ការដំឡើង
composer require leap-lyhour/lighthouse-graphql-sanctum-auth
Quick Start / ចាប់ផ្តើមរហ័ស
# Install package # ដំឡើង package composer require leap-lyhour/lighthouse-graphql-sanctum-auth # Publish configuration # Publish configuration php artisan vendor:publish --tag=lighthouse-sanctum-auth-config # Publish migrations # Publish migrations php artisan vendor:publish --tag=lighthouse-sanctum-auth-migrations # Run migrations # ប្រតិបត្តិ migrations php artisan migrate # Seed permissions and roles (optional) # Seed permissions និង roles (ជម្រើស) php artisan db:seed --class="LeapLyhour\\LighthouseGraphQLSanctumAuth\\Database\\Seeders\\PermissionSeeder"
Configuration / ការកំណត់
Publish the configuration file: Publish file កំណត់:
php artisan vendor:publish --tag=lighthouse-sanctum-auth-config
This will create config/lighthouse-sanctum-auth.php in your application.
នេះនឹងបង្កើត config/lighthouse-sanctum-auth.php ក្នុង application របស់អ្នក។
For detailed configuration options, see Configuration Guide. សម្រាប់ការកំណត់លម្អិត, មើល មគ្គុទេសក៍ការកំណត់។
Usage / ការប្រើ
GraphQL Schema / GraphQL Schema
The package provides authentication mutations and queries: Package ផ្តល់ authentication mutations និង queries:
type Query { me: User @auth } type Mutation { login(email: String!, password: String!, device_name: String): AuthPayload! refreshToken(refresh_token: String!): RefreshTokenPayload! logout: Boolean! @auth }
Authentication Example / ឧទាហរណ៍ Authentication
# Login mutation { login( email: "user@example.com" password: "password" device_name: "iPhone 14" ) { user { id name email roles { name } permissions { name } } token token_type } } # Get current user query { me { id name email roles { name } permissions { name } } }
Directives / Directives
@hasRole
Restrict access to users with specific roles: កំណត់ការចូលប្រើប្រាស់ទៅ users ដែលមាន roles ជាក់លាក់:
type Query { adminUsers: [User!]! @hasRole(role: "admin") } type Mutation { deleteUser(id: ID!): User! @hasRole(role: "admin") }
@hasPermission
Restrict access to users with specific permissions: កំណត់ការចូលប្រើប្រាស់ទៅ users ដែលមាន permissions ជាក់លាក់:
type Mutation { deleteUser(id: ID!): User! @hasPermission(permission: "delete users") editPost(id: ID!, input: PostInput!): Post! @hasPermission(permission: "edit posts") }
@ownership
Ensure users can only access resources they own: ធានាថា users អាចចូលប្រើ resources ដែលពួកគេជាម្ចាស់ប៉ុណ្ណោះ:
type Query { myPost(id: ID!): Post @ownership(relation: "user_id") } type Mutation { updateMyPost(id: ID!, input: PostInput!): Post! @ownership(relation: "user_id") }
@belongsToTenant
Ensure resources belong to the current tenant: ធានាថា resources ជាកម្មសិទ្ធិរបស់ tenant បច្ចុប្បន្ន:
type Query { posts: [Post!]! @belongsToTenant } type Mutation { createPost(input: PostInput!): Post! @belongsToTenant }
@audit
Log field access and mutations: កត់ត្រា field access និង mutations:
type Mutation { deleteUser(id: ID!): User! @audit(action: "delete") createPost(input: PostInput!): Post! @audit(action: "create") updatePost(id: ID!, input: PostInput!): Post! @audit(action: "update") }
Combining Directives / ការរួមបញ្ចូល Directives
You can combine multiple directives for enhanced security: អ្នកអាចរួមបញ្ចូល directives ច្រើនសម្រាប់ security កាន់តែប្រសើរ:
type Mutation { # Requires permission AND logs the action # ត្រូវការ permission និងកត់ត្រា action deletePost(id: ID!): Post! @hasPermission(permission: "delete posts") @audit(action: "delete") # Requires role AND ownership AND logs # ត្រូវការ role និង ownership និងកត់ត្រា updateMyPost(id: ID!, input: PostInput!): Post! @hasRole(role: "editor") @ownership(relation: "user_id") @audit(action: "update") }
Requirements / តម្រូវការ
- PHP >= 8.2
- Laravel >= 12.0
- Lighthouse >= 6.0
- Sanctum >= 4.0
- Spatie Permission >= 6.0
Documentation / Documentation
Complete documentation is available in the docs directory:
Documentation ពេញលេញមាននៅក្នុង directory docs:
- 📖 Installation Guide / មគ្គុទេសក៍ការដំឡើង
- ⚙️ Configuration Guide / មគ្គុទេសក៍ការកំណត់
- 🔐 Authentication Guide / មគ្គុទេសក៍ Authentication
- 👥 Permissions & Roles Guide / មគ្គុទេសក៍ Permissions & Roles
- 🎯 Directives Guide / មគ្គុទេសក៍ Directives
- 🏢 Multi-Tenancy Guide / មគ្គុទេសក៍ Multi-Tenancy
- 📱 Device Management Guide / មគ្គុទេសក៍ការគ្រប់គ្រង Device
- 🛠️ Helpers Guide / មគ្គុទេសក៍ Helpers
- 🔧 Traits & Models Guide / មគ្គុទេសក៍ Traits & Models
- 📋 Audit Logging Guide / មគ្គុទេសក៍ Audit Logging
- 💻 Frontend Integration / ការរួមបញ្ចូល Frontend
- 📚 API Reference / ឯកសារ API
- 🐛 Troubleshooting / ការដោះស្រាយបញ្ហា
Quick Examples / ឧទាហរណ៍រហ័ស
User Model Setup / ការរៀបចំ User Model
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Spatie\Permission\Traits\HasRoles; use Laravel\Sanctum\HasApiTokens; use LeapLyhour\LighthouseGraphQLSanctumAuth\Support\Traits\HasDevices; class User extends Authenticatable { use HasApiTokens, HasRoles, HasDevices; // ... your code }
Using Helpers / ការប្រើ Helpers
use LeapLyhour\LighthouseGraphQLSanctumAuth\Support\Helpers\AuthHelper; use LeapLyhour\LighthouseGraphQLSanctumAuth\Support\Helpers\PermissionHelper; // Check authentication // ពិនិត្យ authentication if (AuthHelper::check()) { $user = AuthHelper::user(); } // Check role // ពិនិត្យ role if (AuthHelper::hasRole('admin')) { // User is admin } // Check permission // ពិនិត្យ permission if (AuthHelper::hasPermission('edit posts')) { // User can edit posts } // Find or create role // រក ឬបង្កើត role $role = PermissionHelper::findOrCreateRole('editor');
Testing / ការធ្វើតេស្ត
# Run tests # ប្រតិបត្តិ tests composer test # Run tests with coverage # ប្រតិបត្តិ tests ជាមួយ coverage composer test-coverage
Contributing / ការរួមចំណែក
Contributions are welcome! Please feel free to submit a Pull Request. ការរួមចំណែកត្រូវបានស្វាគមន៍! សូម submit Pull Request។
Changelog / ប្រវត្តិការផ្លាស់ប្តូរ
Please see CHANGELOG.md for more information on what has changed recently. សូមមើល CHANGELOG.md សម្រាប់ព័ត៌មានបន្ថែមអំពីការផ្លាស់ប្តូរថ្មីៗ។
Security / សុវត្ថិភាព
If you discover any security-related issues, please email leaplyhour2013@gmail.com instead of using the issue tracker.
ប្រសិនបើអ្នករកឃើញបញ្ហាទាក់ទងនឹងសុវត្ថិភាព, សូមផ្ញើ email ទៅ leaplyhour2013@gmail.com ជំនួសឱ្យការប្រើ issue tracker។
Credits / ការទទួលស្គាល់
- Author: Leap Lyhour
- Email: leaplyhour2013@gmail.com
- License: MIT
License / អាជ្ញាប័ណ្ឌ
This package is open-sourced software licensed under the MIT license. Package នេះជា open-sourced software ដែលមាន license ក្រោម MIT license។
leap-lyhour/lighthouse-graphql-sanctum-auth 适用场景与选型建议
leap-lyhour/lighthouse-graphql-sanctum-auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「authorization」 「security」 「api」 「Authentication」 「Audit」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 leap-lyhour/lighthouse-graphql-sanctum-auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 leap-lyhour/lighthouse-graphql-sanctum-auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 leap-lyhour/lighthouse-graphql-sanctum-auth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Provide a way to secure accesses to all routes of an symfony application.
A PSR-7 compatible library for making CRUD API endpoints
It's a barebone security class written on PHP
Laravel JWT auth service package
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-17