Skip to content

Latest commit

 

History

History
179 lines (126 loc) · 5.04 KB

Installation.md

File metadata and controls

179 lines (126 loc) · 5.04 KB

Installation

Prerequisites

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.

Install the SDK

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.

Using Quickstart (Recommended)

  • Create a new Laravel 9 project pre-configured with the SDK:

    composer create-project auth0-samples/laravel auth0-laravel-app

Installation with Composer

Create a Laravel Application

  • 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

Install the SDK

  1. Run the following command from your project directory to install the SDK:

    composer require auth0/login:^7.8 --update-with-all-dependencies
  2. Generate an SDK configuration file for your application:

    php artisan vendor:publish --tag auth0

Install the CLI

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

  • Authenticate the CLI with your Auth0 account. Choose "as a user," and follow the prompts.

    auth0 login

Configure the SDK

Using JSON (Recommended)

  1. 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
  2. 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
  3. 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

Using Environment Variables

  1. 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 and client_secret values in the output.

  2. 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
  3. 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.