codebarista/laravel-workos
最新稳定版本:1.2.3
Composer 安装命令:
composer require codebarista/laravel-workos
包简介
Authorize Laravel users with WorkOS.
README 文档
README
User Roles, Permissions and Stripe Entitlements
Authorize users with WorkOS roles and permissions, as well as subscribed Stripe entitlements. The roles and permissions implementation is heavily inspired by Spatie Laravel Permission. The additional Stripe entitlements are applied in the same way as permissions.
1. Installation
composer require codebarista/laravel-workos
2. Configuration
WorkOS
These variables should match the values provided to you in the WorkOS dashboard for your application:
WORKOS_REDIRECT_URL="${APP_URL}/authenticate" WORKOS_CLIENT_ID=your-client-id WORKOS_API_KEY=your-api-key
Routes
LARAVEL_WORKOS_ROUTES_AUTHENTICATE=authenticate LARAVEL_WORKOS_REDIRECT_TO_ROUTE_NAME=dashboard LARAVEL_WORKOS_ROUTES_LOGOUT=logout LARAVEL_WORKOS_ROUTES_LOGIN=login
Publish config (optional)
php artisan vendor:publish --tag="config" --provider="Codebarista\LaravelWorkos\LaravelWorkosServiceProvider"
3. Implementation
Add the HasRoles, HasPermissions and HasEntitlements traits as needed to the User class, or any other that
uses authentication.
namespace App\Models; use Codebarista\LaravelWorkos\Traits\HasEntitlements; use Codebarista\LaravelWorkos\Traits\HasPermissions; use Codebarista\LaravelWorkos\Traits\HasRoles; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasEntitlements, HasPermissions, HasRoles; // ... }
4. Usage
WorkOS Role & Permissions
// e.g. use in Laravel policies class EntryPolicy { public function viewAny(User $user): bool { return $user->hasPermissionTo('entries:view') // custom WorkOS permission || $user->hasRole('org-editor'); // custom WorkOS organization role } // ... }
Stripe Product Entitlements
Register Stripe customer for entitlements
php artisan codebarista:register-stripe-customer
Authorize with Stripe product entitlements
// e.g. use in Laravel gates protected function gate(): void { Gate::define('viewNova', static function (User $user) { return $user->hasEntitlementTo('access-dashboard'); // custom Stripe entitlement }); }
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 86
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-23