omnifyjp/omnify-client-laravel-sso
Composer 安装命令:
composer require omnifyjp/omnify-client-laravel-sso
包简介
SSO Client Package for Laravel - Provides Role, Permission and RolePermission models with Omnify schema-driven development
关键字:
README 文档
README
Laravel package for Single Sign-On (SSO) integration with Omnify Console, featuring Role-Based Access Control (RBAC), team permissions, and comprehensive security features.
Features
- SSO Authentication - JWT-based authentication with Omnify Console
- UUID Support - All models use UUID primary keys (compatible with Console)
- Role-Based Access Control (RBAC) - Flexible role and permission management
- Team Permissions - Organization-level permission management via Console
- Minimal Schema Design - Only stores Console references, data is fetched from Console API
- Security - Open redirect protection, input validation, rate limiting ready
- Logging - Dedicated log channel for audit trails
- Multi-language - i18n support (ja, en, vi)
- Omnify Schema-Driven - Auto-generated models with Omnify
Architecture
This package integrates with Omnify Console's ServiceInstance architecture:
Console (SSO Provider) Your Service (SSO Client)
┌─────────────────────────────┐ ┌─────────────────────────┐
│ Users (UUID) │ │ users │
│ Organizations (UUID) │◀────────▶│ console_user_id (UUID)│
│ Teams (UUID) │ │ │
│ Branches (UUID) │ │ teams │
│ │ │ console_team_id (UUID)│
│ Service: "your-service" │ │ console_org_id (UUID) │
│ │ │ │
│ ServiceInstance (per-org): │ │ branches │
│ - client_id │ │ console_branch_id │
│ - client_secret │ │ console_org_id (UUID) │
└─────────────────────────────┘ └─────────────────────────┘
Design Philosophy: This package only stores Console reference IDs. Full user/team/branch data is fetched from Console API when needed, ensuring data consistency.
Requirements
- PHP 8.2+
- Laravel 11.0+ or 12.0+
- MySQL 8.0+ / PostgreSQL 13+ / SQLite 3.35+
Quick Start
1. Install
composer require omnifyjp/omnify-client-laravel-sso
2. Configure Environment
# Required SSO_CONSOLE_URL=https://console.omnify.jp SSO_SERVICE_SLUG=your-service-slug # Optional SSO_LOG_CHANNEL=sso SSO_LOGGING_ENABLED=true
3. Run Migrations
php artisan migrate
4. Install Command (Optional)
php artisan sso:install
Models
All models use UUID primary keys for compatibility with Console.
| Model | Description | Console Reference |
|---|---|---|
User |
SSO user with Console integration | console_user_id (UUID) |
Branch |
Branch reference from Console | console_branch_id, console_org_id (UUID) |
Team |
Team reference from Console | console_team_id, console_org_id (UUID) |
TeamPermission |
Team-level permissions | console_team_id, console_org_id (UUID) |
Role |
Local role with level hierarchy | - |
Permission |
Local permission | - |
RolePermission |
Role-Permission pivot | - |
User Model Fields
// SSO fields only - basic auth fields come from your main User schema $fillable = [ 'console_user_id', // UUID - links to Console User 'console_access_token', // Encrypted access token 'console_refresh_token', // Encrypted refresh token 'console_token_expires_at', 'role_id', // UUID - local role assignment ];
Branch/Team Model Fields
// Only Console references - full data fetched from Console API $fillable = [ 'console_branch_id', // UUID - links to Console Branch 'console_org_id', // UUID - links to Console Organization ];
Omnify Schema Integration
This package uses Omnify for schema-driven development. Schemas are designed as kind: object with minimal fields:
# database/schemas/Sso/User.yaml kind: object options: timestamps: true idType: Uuid properties: console_user_id: type: Uuid unique: true nullable: true console_access_token: type: Text nullable: true # ... other SSO fields role: type: Association relation: ManyToOne target: Role
Generate Models
# In your project npx omnify generate # Output: Auto-discovered packages from .omnify-packages.json
Usage Examples
Authentication Flow
// Frontend redirects to Console login $loginUrl = "https://console.omnify.jp/sso/authorize?" . http_build_query([ 'service' => config('sso-client.service.slug'), 'redirect_uri' => url('/sso/callback'), ]); // After login, Console redirects back with code // POST /api/sso/callback { "code": "authorization_code" }
Check Permissions
$user = auth()->user(); // Check single permission if ($user->hasPermission('users.create')) { // ... } // Check any permission if ($user->hasAnyPermission(['users.create', 'users.update'])) { // ... } // Via Gate if (Gate::allows('users.create')) { // ... } // Via Blade @can('users.create') <button>Create User</button> @endcan
Protect Routes
Route::middleware(['sso.auth', 'sso.permission:users.create'])->group(function () { Route::post('/users', [UserController::class, 'store']); }); // Role-based protection Route::middleware(['sso.auth', 'sso.role:admin'])->group(function () { Route::resource('/admin/settings', SettingsController::class); });
Fetch Data from Console
use Omnify\SsoClient\Services\ConsoleApiService; $consoleApi = app(ConsoleApiService::class); // Get user details from Console $consoleUser = $consoleApi->getUser($user->console_user_id); // Get organization teams $teams = $consoleApi->getOrganizationTeams($orgId); // Get branch details $branch = $consoleApi->getBranch($branchId);
Package Structure
omnify-client-laravel-sso/
├── config/
│ └── sso-client.php # Configuration
├── database/
│ ├── factories/ # Model factories
│ ├── migrations/ # Database migrations
│ └── schemas/Sso/ # Omnify schema definitions
│ ├── User.yaml # SSO fields for User
│ ├── Branch.yaml # Console branch reference
│ ├── Team.yaml # Console team reference
│ ├── TeamPermission.yaml # Team permissions
│ ├── Role.yaml # Local roles
│ ├── Permission.yaml # Local permissions
│ └── RolePermission.yaml # Role-Permission pivot
├── src/
│ ├── Models/
│ │ ├── OmnifyBase/ # Auto-generated base models (UUID support)
│ │ ├── User.php # User model
│ │ ├── Branch.php # Branch model
│ │ ├── Team.php # Team model
│ │ └── ...
│ ├── Services/
│ │ ├── ConsoleApiService.php # Console API client
│ │ ├── ConsoleTokenService.php # Token management
│ │ └── ...
│ └── Http/
│ ├── Controllers/ # API controllers
│ └── Middleware/ # Route middleware
└── tests/ # Test suite
Available Commands
# Install package php artisan sso:install # Sync permissions from config php artisan sso:sync-permissions # Cleanup orphaned teams php artisan sso:cleanup-orphan-teams
Database Seeders
The package includes reusable seeders for roles and permissions:
// In your DatabaseSeeder.php use Omnify\SsoClient\Database\Seeders\SsoRolesSeeder; $this->call(SsoRolesSeeder::class);
This creates:
- 5 roles: admin, manager, supervisor, member, viewer
- 21 permissions: service-admin., dashboard.
For app-specific permissions, use the provided traits:
use Omnify\SsoClient\Database\Seeders\Concerns\AssignsRoles; use Omnify\SsoClient\Database\Seeders\Concerns\FetchesConsoleData; class PermissionSeeder extends Seeder { use FetchesConsoleData, AssignsRoles; public function run(): void { // Fetch org data dynamically from Console $orgData = $this->fetchOrgDataFromConsole('your-org-slug'); // Assign role to user $this->assignRoleToUserByEmail('admin@example.com', 'admin', $orgData['org_id']); } }
See Seeders Documentation for full details.
Documentation
| Document | Description |
|---|---|
| Installation | Detailed installation guide |
| Configuration | All configuration options |
| Authentication | SSO flow and JWT verification |
| Authorization | RBAC, roles, and permissions |
| Middleware | Available middleware |
| API Reference | Admin API endpoints |
| Seeders | Roles, permissions, and traits |
Testing
./vendor/bin/pest
License
MIT License. See LICENSE for more information.
Credits
- Omnify Team
- Generated with Omnify
omnifyjp/omnify-client-laravel-sso 适用场景与选型建议
omnifyjp/omnify-client-laravel-sso 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 101 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「authorization」 「Authentication」 「SSO」 「laravel」 「roles」 「permissions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 omnifyjp/omnify-client-laravel-sso 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 omnifyjp/omnify-client-laravel-sso 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 omnifyjp/omnify-client-laravel-sso 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
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.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Email Toolkit Plugin for CakePHP
统计信息
- 总下载量: 101
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-16