workos/workos-php-laravel
Laravel integration for the WorkOS API. Provides a configured WorkOS client via service provider, facade, helper, or dependency injection to access services like User Management and SSO. Install with Composer and set WORKOS_API_KEY and WORKOS_CLIENT_ID.
workos/workos-php SDK, leveraging Laravel’s service container, facades, and dependency injection for seamless integration. This aligns well with Laravel’s architectural patterns (e.g., WorkOS::userManagement() or DI via constructor injection).WorkOS facade (WorkOS::userManagement()) reduces boilerplate, improving developer ergonomics while maintaining testability via DI.Authenticated, UserCreated), enabling reactive workflows (e.g., provisioning users in third-party systems).WORKOS_API_KEY and WORKOS_CLIENT_ID, which is a secure, standard practice but requires CI/CD and deployment pipeline updates.vendor:publish step for configuration is Laravel-idiomatic but may need customization for teams with non-standard .env setups.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Breaking Changes | Major versions (e.g., v6+) introduce API surface changes (e.g., mfa() → multiFactorAuth()). |
Pin to a stable minor version (e.g., 7.x.x) and monitor changelogs for deprecations. |
| Dependency Bloat | Underlying workos/workos-php may introduce unnecessary dependencies (e.g., Guzzle). |
Audit composer.json for transitive dependencies and test performance impact. |
| Error Handling | WorkOS API errors (e.g., 4xx/5xx) may not map cleanly to Laravel’s exception hierarchy. | Wrap API calls in try-catch blocks and translate errors to Laravel’s ProblemException or custom exceptions. |
| Testing Complexity | Mocking WorkOS APIs in tests requires stubbing HTTP clients (e.g., Guzzle). | Use Laravel’s Mockery or Pest to mock the WorkOS facade or DI-bound client. |
| Rate Limiting | WorkOS APIs have rate limits; unoptimized calls could trigger throttling. | Implement exponential backoff and cache responses (e.g., Cache::remember). |
Adoption Scope:
users table?Authentication Flow:
Auth::attempt() vs. WorkOS callbacks)?Data Synchronization:
user.updated)?Performance:
Compliance:
Fallbacks:
WorkOS client bound to the container.WorkOS::userManagement() for concise syntax.WorkOS\Events\UserSynced).dispatch()).| Step | Action | Tools/Commands |
|---|---|---|
| 1. Pre-Integration | Audit Laravel version (must be 10+). Upgrade if needed. | composer require laravel/framework:^10.0 |
| 2. Install Package | Add to composer.json and publish config. |
composer require workos/workos-php-laravel php artisan vendor:publish --provider="WorkOS\Laravel\WorkOSServiceProvider" |
| 3. Configure | Set WORKOS_API_KEY and WORKOS_CLIENT_ID in .env. |
.env file |
| 4. Test Core Workflows | Verify SSO login, user management, and webhooks in a staging environment. | Laravel’s php artisan test or manual testing. |
| 5. Migrate Existing Auth | Replace custom auth logic with WorkOS (e.g., swap Auth::attempt() for WorkOS SSO). |
Refactor app/Http/Controllers/Auth/ and routes/auth.php. |
| 6. Directory Sync (Optional) | Sync local users to WorkOS or vice versa. | Custom Artisan command or queue job. |
| 7. Webhook Setup | Configure WorkOS webhooks to trigger Laravel events/queue jobs. | php artisan make:event WorkOSUserSynced WorkOS Dashboard → Webhooks. |
| 8. Monitoring | Add logging for WorkOS API calls and errors. | Laravel’s Log::channel('single') or third-party APM (e.g., Sentry). |
.env for WORKOS_API_KEY leaks (use Laravel’s env() caching cautiously).How can I help you explore Laravel packages today?