Documentation Index
Fetch the complete documentation index at: https://docs-staging.auth0-mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Use AI to integrate Auth0
Use AI to integrate Auth0
auth0/login, configure environment variables, and register authentication routes. Full agent skills documentation →Get Started
This quickstart demonstrates how to add Auth0 authentication to a Laravel application. You’ll configure secure login, logout, protected routes, and user profile access using the Auth0 Laravel SDK.Create a new Laravel project
Install the Auth0 Laravel SDK
Configure Auth0 credentials
- Quick Setup (recommended)
- CLI
- Dashboard
.env credentials with the right configuration values.Add these values to your project’s .env file:Add authentication routes
| Route | Purpose |
|---|---|
/login | Initiates the Auth0 login flow |
/logout | Logs out the user and redirects to Auth0 |
/callback | Handles the Auth0 authentication callback |
/login, /logout, and /callback routes may conflict with routes registered by those packages. See the SDK README for instructions on manual route registration.routes/web.php to add your home route:Protect routes with middleware
auth middleware to require authentication on any route. You can also enforce specific permissions using the can middleware:Run your application
php artisan serve --port=8001 and update your Auth0 application’s Allowed Callback URLs and Allowed Logout URLs to use the new port.- http://localhost:8000/login — triggers the Auth0 login flow
- http://localhost:8000/private — redirects to login if unauthenticated; shows a welcome message when logged in
- http://localhost:8000/logout — logs out and returns to the home page
Troubleshooting
Callback URL mismatch error
Callback URL mismatch error
- Go to the Auth0 Dashboard → Applications > Applications → your app → Settings
- Add
http://localhost:8000/callbackto Allowed Callback URLs - Click Save Changes
Invalid state / CSRF error after login
Invalid state / CSRF error after login
- Ensure your
SESSION_DRIVERin.envis set tofile,database, orredis(notarray) - Clear the config and cache:
- Restart your development server
AUTH0_DOMAIN not set or credentials not loading
AUTH0_DOMAIN not set or credentials not loading
- A
.envfile withAUTH0_DOMAIN,AUTH0_CLIENT_ID, andAUTH0_CLIENT_SECRET - A
.auth0.app.jsonfile generated by the Auth0 CLI
.env, clear the config cache:404 on /login, /logout, or /callback
404 on /login, /logout, or /callback
- Confirm you ran
php artisan vendor:publish --tag auth0 - Verify package auto-discovery is enabled (check
composer.jsonfor"dont-discover": []) - Run
php artisan route:list | grep auth0to confirm the routes are registered - If routes are missing, manually register the service provider. In Laravel 11+, add it to
bootstrap/providers.php:
Advanced Usage
Management API — update user metadata
Management API — update user metadata
Auth0::management() method.Before making Management API calls, authorize your application to access the Management API:- Go to the Auth0 Dashboard → Applications > APIs → Auth0 Management API
- Select the Machine to Machine Applications tab
- Authorize your Laravel application and grant the
read:usersandupdate:usersscopes
Custom user models and repositories
Custom user models and repositories
Listening to SDK events
Listening to SDK events
Role-Based Access Control (RBAC)
Role-Based Access Control (RBAC)
can middleware:- Go to the Auth0 Dashboard → Applications > APIs → your API → Permissions
- Add the permissions your application needs (e.g.,
admin:dashboard,read:messages) - Go to User Management > Roles, create a role, and assign permissions to it
- Assign the role to users from their profile page
Next Steps
Now that you have authentication working in your Laravel application, explore more Auth0 features:- Auth0 Dashboard — Configure and manage your Auth0 tenant and applications
- laravel-auth0 SDK — Full SDK documentation and advanced integrations
- Role-Based Access Control — Assign permissions to users with roles
- Auth0 Marketplace — Discover integrations to extend Auth0’s functionality