Integrating WorkOS with Laravel
Integrating WorkOS with Laravel
Integrating WorkOS with Laravel enhances your application's authentication capabilities, offering features like social logins, passkeys, and Single Sign-On (SSO). Laravel provides starter kits for React, Vue, and Livewire, each with a WorkOS AuthKit variant, simplifying the integration process.
Getting Started with WorkOS and Laravel Integration
1. Install Laravel
Begin by installing Laravel using the Laravel installer. If you haven't updated the installer recently, do so with:
composer global require laravel/installer
Next, create a new Laravel project:
laravel new my-app
During setup, you'll be prompted to select a starter kit. Choose your preferred frontend framework (React, Vue, or Livewire) and opt for the WorkOS AuthKit variant when asked.
2. Configure WorkOS in Laravel
After installation, configure your environment variables with your WorkOS API credentials. Update your .env
file with the following:
WORKOS_CLIENT_ID=client_XXXXXXXXX
WORKOS_API_KEY=sk_test_XXXXXXXXX
WORKOS_REDIRECT_URL=http://localhost:8000/authenticate
Replace the placeholders with your actual WorkOS credentials
3: Set Up Redirects in WorkOS
In your WorkOS dashboard, configure the redirect URIs:
- Sign-in callback:
http://localhost:8000/authenticate
- App homepage URL:
http://localhost:8000/
- Logout redirect URL:
http://localhost:8000/
Ensure these URLs match your application's routes.
4: Customize Authentication Methods
Within the WorkOS AuthKit settings, disable the "Email + Password" authentication if you prefer users to authenticate solely via social providers, passkeys, Magic Auth, or SSO. This approach enhances security by eliminating password handling within your application.
5: Align Session Timeouts
To maintain session consistency, configure the AuthKit session inactivity timeout to match your Laravel application's session timeout settings.
6: Launch the Application
Start your Laravel development server:
php artisan serve
Access your application at http://localhost:8000/ to verify the integration. The authentication system should now support WorkOS features seamlessly.
For a visual walkthrough, consider watching the following tutorial: