laravel-workos maintained by codebarista
Description
Authorize Laravel users with WorkOS.
Author
Last update
2026/03/04 13:58
(dev-main)
License
Downloads
90
Tags
Laravel WorkOS
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.