Your application must use the latest supported Laravel version, and your host environment must be running a supported PHP version. Please review our support policy for more information. You will also need Composer 2.0+ and an Auth0 account.
Ensure that your development environment has supported versions of PHP and Composer installed. If you're using macOS, PHP and Composer can be installed via Homebrew. It's also advisable to install Node and NPM.
-
Create a new Laravel 9 project pre-configured with the SDK:
composer create-project auth0-samples/laravel auth0-laravel-app
-
If you do not already have one, you can Create a new Laravel 9 application with the following command:
composer create-project laravel/laravel:^9.0 auth0-laravel-app
-
Run the following command from your project directory to install the SDK:
composer require auth0/login:^7.8 --update-with-all-dependencies
-
Generate an SDK configuration file for your application:
php artisan vendor:publish --tag auth0
Install the Auth0 CLI to create and manage Auth0 resources from the command line.
-
macOS with Homebrew:
brew tap auth0/auth0-cli && brew install auth0
-
Linux or macOS:
curl -sSfL https://raw.githubusercontent.com/auth0/auth0-cli/main/install.sh | sh -s -- -b . sudo mv ./auth0 /usr/local/bin
-
Windows with Scoop:
scoop bucket add auth0 https://github.com/auth0/scoop-auth0-cli.git scoop install auth0
-
Authenticate the CLI with your Auth0 account. Choose "as a user," and follow the prompts.
auth0 login
-
Register a new application with Auth0:
auth0 apps create \ --name "My Laravel Application" \ --type "regular" \ --auth-method "post" \ --callbacks "http://localhost:8000/callback" \ --logout-urls "http://localhost:8000" \ --reveal-secrets \ --no-input \ --json > .auth0.app.json
-
Register a new API with Auth0:
auth0 apis create \ --name "My Laravel Application API" \ --identifier "https://github.com/auth0/laravel-auth0" \ --offline-access \ --no-input \ --json > .auth0.api.json
-
Add the new files to
.gitignore
:Linux and macOS:
echo ".auth0.*.json" >> .gitignore
Windows PowerShell:
Add-Content .gitignore "`n.auth0.*.json"
Windows Command Prompt:
echo .auth0.*.json >> .gitignore
-
Register a new application with Auth0:
auth0 apps create \ --name "My Laravel Application" \ --type "regular" \ --auth-method "post" \ --callbacks "http://localhost:8000/callback" \ --logout-urls "http://localhost:8000" \ --reveal-secrets \ --no-input
Make a note of the
client_id
andclient_secret
values in the output. -
Register a new API with Auth0:
auth0 apis create \ --name "My Laravel Application API" \ --identifier "https://github.com/auth0/laravel-auth0" \ --offline-access \ --no-input
-
Open the
.env
file found inside your project directory, and add the following lines, replacing the values with the ones you noted in the previous steps:# The Auth0 domain for your tenant (e.g. tenant.region.auth0.com): AUTH0_DOMAIN=... # The application `client_id` you noted above: AUTH0_CLIENT_ID=... # The application `client_secret` you noted above: AUTH0_CLIENT_SECRET=... # The API `identifier` you used above: AUTH0_AUDIENCE=...
Additional configuration environment variables can be found in the configuration guide.