2017 © Pedro Pelรกez
 

library login

Laravel plugin that helps authenticate with the auth0 service

image

auth0/login

Laravel plugin that helps authenticate with the auth0 service

  • Tuesday, March 20, 2018
  • by hrajchert
  • Repository
  • 75 Watchers
  • 64 Stars
  • 165,506 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 49 Forks
  • 10 Open issues
  • 50 Versions
  • 16 % Grown

The README.md

Auth0 Laravel SDK, (*1)

The Auth0 Laravel SDK is a PHP package that integrates Auth0 into your Laravel application. It includes no-code user authentication, extensive Management API support, permissions-based routing access control, and more., (*3)

Requirements

Your application must use a supported Laravel version, and your host environment must be running a maintained PHP version. Please review our support policy for more information., (*4)

You will also need Composer and an Auth0 account., (*5)

Supported Laravel Releases

The next major release of Laravel is forecasted for Q1 2025. We anticipate supporting it upon release., (*6)

Laravel SDK PHP Supported Until
12.x 7.15+ 8.4 Approx. Feb 2027 (EOL for Laravel 12)
8.2 Approx. Dec 2025 (EOL for PHP 8.3)

We strive to support all actively maintained Laravel releases, prioritizing support for the latest major version with our SDK. If a new Laravel major introduces breaking changes, we may have to end support for past Laravel versions earlier than planned., (*7)

Affected Laravel versions will still receive security fixes until their end-of-life date, as announced in our release notes., (*8)

Maintenance Releases

The following releases are no longer being updated with new features by Auth0, but will continue to receive security updates through their end-of-life date., (*9)

Laravel SDK PHP Security Fixes Until
11.x 7.13+ 8.4 March 2026 (EOL for Laravel 11)
8.3 March 2026 (EOL for Laravel 11)
8.2 Dec 2026 (EOL for PHP 8.2)

Unsupported Releases

The following releases are unsupported by Auth0. While they may be suitable for some legacy applications, your mileage may vary. We recommend upgrading to a supported version as soon as possible., (*10)

Laravel SDK
10.x 7.5 - 7.12
9.x 7.0 - 7.12
8.x 7.0 - 7.4
7.x 5.4 - 6.5
6.x 5.3 - 6.5
5.x 2.0 - 6.1
4.x 1.x

Getting Started

The following is our recommended approach to getting started with the SDK. Alternatives are available in our expanded installation guide., (*11)

1. Install the SDK

  • For new applications, we offer a quickstart template โ€” a version of the default Laravel 9 starter project pre-configured for use with the Auth0 SDK., (*12)

    composer create-project auth0-samples/laravel auth0-laravel-app && cd auth0-laravel-app
    
  • For existing applications, you can install the SDK using Composer., (*13)

    composer require auth0/login:^7 --update-with-all-dependencies
    

    In this case, you will also need to generate an SDK configuration file for your application., (*14)

    php artisan vendor:publish --tag auth0
    

, (*15)

2. Install the CLI

  1. Install the Auth0 CLI to manage your account from the command line., (*16)

    curl -sSfL https://raw.githubusercontent.com/auth0/auth0-cli/main/install.sh | sh -s -- -b .
    

    Move the CLI to a directory in your PATH to make it available system-wide., (*17)

    sudo mv ./auth0 /usr/local/bin
    

    ๐Ÿ’ก If you prefer not to move the CLI, simply substitute `auth0` in the CLI steps below with `./auth0`., (*18)

    Using Homebrew (macOS) โ€ƒ
    , (*19)

    brew tap auth0/auth0-cli && brew install auth0
    

    , (*20)

    Using Scoop (Windows) โ€ƒ
    , (*21)

    scoop bucket add auth0 https://github.com/auth0/scoop-auth0-cli.git
    scoop install auth0
    

    , (*22)

  2. Authenticate the CLI with your Auth0 account. Choose "as a user" if prompted., (*23)

    auth0 login
    

3. Configure the SDK

  1. Register a new application with Auth0., (*24)

    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., (*25)

    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., (*26)

    echo ".auth0.*.json" >> .gitignore
    

    Using Windows PowerShell โ€ƒ
    , (*27)

    Add-Content .gitignore "`n.auth0.*.json"
    

    , (*28)

    Using Windows Command Prompt โ€ƒ
    , (*29)

    echo .auth0.*.json >> .gitignore
    

    , (*30)

4. Run the Application

Boot the application using PHP's built-in web server., (*31)

php artisan serve

Direct your browser to http://localhost:8000 to experiment with the application., (*32)

  • Authentication
    Users can log in or out of the application by visiting the /login or /logout routes, respectively., (*33)

  • API Authorization
    For simplicity sake, generate a test token using the CLI., (*34)

    auth0 test token \
      --audience %IDENTIFIER% \
      --scopes "read:messages"
    

    โœ‹ Substitute %IDENTIFIER% with the identifier of the API you created in step 3 above., (*35)

    Now you can send requests to the /api endpoints of the application, including the token as a header., (*36)

    curl --request GET \
      --url http://localhost:8000/api/example \
      --header 'Accept: application/json' \
      --header 'Authorization: Bearer %TOKEN%'
    

    , (*37)

    โœ‹ Substitute %TOKEN% with the test token returned in the previous step., (*38)

    Using Windows PowerShell โ€ƒ
    , (*39)

    Invoke-WebRequest http://localhost:8000/api/example `
      -Headers @{'Accept' = 'application/json'; 'Authorization' = 'Bearer %TOKEN%'}
    

    , (*40)

When you're ready to deploy your application to production, review our deployment guide for best practices and advice on securing Laravel., (*41)

Integration Examples

User Authentication โ€ƒ
, (*42)

The SDK automatically registers all the necessary routes and authentication services within the web middleware group of your application to enable users to authenticate without requiring you to write any code., (*43)

Route Purpose
/login Initiates the authentication flow.
/logout Logs the user out.
/callback Handles the callback from Auth0.

If these routes conflict with your application architecture, you can override this default behavior by adjusting the SDK configuration., (*44)


, (*45)

Route Authorization (Access Control) โ€ƒ
, (*46)

The SDK automatically registers its authentication and authorization guards within the web and api middleware groups for your Laravel application, respectively., (*47)

For web routes, you can use Laravel's auth middleware to require that a user be authenticated to access a route., (*48)

Route::get('/private', function () {
  return response('Welcome! You are logged in.');
})->middleware('auth');

For api routes, you can use Laravel's auth middleware to require that a request be authenticated with a valid bearer token to access a route., (*49)

Route::get('/api/private', function () {
  return response()->json(['message' => 'Hello! You included a valid token with your request.']);
})->middleware('auth');

In addition to requiring that a user be authenticated, you can also require that the user have specific permissions to access a route, using Laravel's can middleware., (*50)

Route::get('/scope', function () {
    return response('You have the `read:messages` permission, and can therefore access this resource.');
})->middleware('auth')->can('read:messages');

Permissions require that RBAC be enabled within your API settings., (*51)


, (*52)

Users and Tokens โ€ƒ
, (*53)

Laravel's Auth Facade can be used to retrieve information about the authenticated user or token associated with a request., (*54)

For routes using the web middleware group in routes/web.php., (*55)

Route::get('/', function () {
  if (! auth()->check()) {
    return response('You are not logged in.');
  }

  $user = auth()->user();
  $name = $user->name ?? 'User';
  $email = $user->email ?? '';

  return response("Hello {$name}! Your email address is {$email}.");
});

For routes using the api middleware group in routes/api.php., (*56)

Route::get('/', function () {
  if (! auth()->check()) {
    return response()->json([
      'message' => 'You did not provide a token.',
    ]);
  }

  return response()->json([
    'message' => 'Your token is valid; you are authorized.',
    'id' => auth()->id(),
    'token' => auth()?->user()?->getAttributes(),
  ]);
});

, (*57)

Management API Calls โ€ƒ
, (*58)

Once you've authorized your application to make Management API calls, you'll be able to engage nearly any of the Auth0 Management API endpoints through the SDK., (*59)

Each API endpoint has its own SDK class which can be accessed through the Facade's management() factory method. For interoperability, network responses from the API are returned as PSR-7 messages. These can be converted into native arrays using the SDK's json() method., (*60)

For example, to update a user's metadata, you can call the management()->users()->update() method., (*61)

use Auth0\Laravel\Facade\Auth0;

Route::get('/colors', function () {
  $colors = ['red', 'blue', 'green', 'black', 'white', 'yellow', 'purple', 'orange', 'pink', 'brown'];

  // Update the authenticated user with a randomly assigned favorite color.
  Auth0::management()->users()->update(
    id: auth()->id(),
    body: [
      'user_metadata' => [
        'color' => $colors[random_int(0, count($colors) - 1)]
      ]
    ]
  );

  // Retrieve the user's updated profile.
  $profile = Auth0::management()->users()->get(auth()->id());

  // Convert the PSR-7 response into a native array.
  $profile = Auth0::json($profile);

  // Extract some values from the user's profile.
  $color = $profile['user_metadata']['color'] ?? 'unknown';
  $name = auth()->user()->name;

  return response("Hello {$name}! Your favorite color is {$color}.");
})->middleware('auth');

All the SDK's Management API methods are documented here., (*62)

, (*63)

Documentation

  • Installation โ€” Installing the SDK and generating configuration files.
  • Configuration โ€” Configuring the SDK using JSON files or environment variables.
  • Sessions โ€” Guidance on deciding which Laravel Session API driver to use.
  • Cookies โ€” Important notes about using Laravel's Cookie session driver, and alternative options.
  • Management API โ€” Using the SDK to work with the Auth0 Management API.
  • Users โ€” Extending the SDK to support persistent storage and Eloquent models.
  • Events โ€” Hooking into SDK events to respond to specific actions.
  • Deployment โ€” Deploying your application to production.

You may find the following integration guidance useful:, (*64)

You may also find the following resources helpful:, (*65)

Contributions to improve our documentation are welcomed., (*66)

QuickStarts

Community

The Auth0 Community is where you can get support, ask questions, and share your projects., (*67)

Contributing

We appreciate feedback and contributions to this library. Before you get started, please review Auth0's General Contribution guidelines., (*68)

The Contribution Guide contains information about our development process and expectations, insight into how to propose bug fixes and improvements, and instructions on how to build and test changes to the library., (*69)

To provide feedback or report a bug, please raise an issue., (*70)

Code of Conduct

Participants are expected to adhere to Auth0's Code of Conduct when interacting with this project., (*71)

Security

If you believe you have found a security vulnerability, we encourage you to responsibly disclose this and not open a public issue. We will investigate all reports. The Responsible Disclosure Program details the procedure for disclosing security issues., (*72)

License

This library is open-sourced software licensed under the MIT license., (*73)


Auth0 Logo , (*74)

Auth0 is an easy-to-implement, adaptable authentication and authorization platform.
To learn more, check out "Why Auth0?", (*75)

The Versions

20/03 2018

dev-master

9999999-dev

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

20/03 2018

dev-5.x.x-dev

dev-5.x.x-dev

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

20/03 2018

dev-release-5.1.0

dev-release-5.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

20/03 2018

5.1.0

5.1.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

20/03 2018

dev-fix-readme-changelog

dev-fix-readme-changelog

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

19/03 2018

dev-4.x.x-dev

dev-4.x.x-dev

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/03 2018

dev-update-use-auth0-login

dev-update-use-auth0-login

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

22/09 2017

dev-changed-default-scope

dev-changed-default-scope

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

30/08 2017

5.0.2

5.0.2.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

23/02 2017

5.0.1

5.0.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

22/02 2017

5.0.0

5.0.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

27/01 2017

4.0.8

4.0.8.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/01 2017

4.0.7

4.0.7.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

23/12 2016

4.0.6

4.0.6.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

29/11 2016

4.0.5

4.0.5.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

28/11 2016

dev-deprecate-samples

dev-deprecate-samples

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

03/10 2016

4.0.3

4.0.3.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

03/10 2016

4.0.4

4.0.4.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

03/10 2016

4.0.2

4.0.2.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

19/09 2016

4.0.1

4.0.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

15/09 2016

4.0.0

4.0.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

12/09 2016

dev-3.x.x-dev

dev-3.x.x-dev

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

12/09 2016

3.2.1

3.2.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

12/07 2016

3.2.0

3.2.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/05 2016

3.1.0

3.1.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/05 2016

dev-2.x.x-dev

dev-2.x.x-dev

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/05 2016

2.2.1

2.2.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/05 2016

2.3.1

2.3.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

02/05 2016

2.3.2

2.3.2.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

15/04 2016

2.3.0

2.3.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

28/01 2016

3.0.3

3.0.3.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

25/01 2016

3.0.2

3.0.2.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

18/01 2016

3.0.1

3.0.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

06/01 2016

3.0.0

3.0.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

30/11 2015

2.2.0

2.2.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

27/10 2015

2.1.4

2.1.4.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

17/07 2015

2.1.3

2.1.3.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

15/05 2015

2.1.2

2.1.2.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

12/05 2015

2.1.1

2.1.1.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

07/05 2015

2.1.0

2.1.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

07/05 2015

dev-api_v2

dev-api_v2

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

20/04 2015

2.0.0

2.0.0.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

14/04 2015

dev-1.x.x-dev

dev-1.x.x-dev

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

14/04 2015

1.0.8

1.0.8.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

13/04 2015

1.0.7

1.0.7.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

01/08 2014

dev-api-example

dev-api-example

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

01/08 2014

1.0.6

1.0.6.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

01/08 2014

1.0.5

1.0.5.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

07/05 2014

1.0.4

1.0.4.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert

21/04 2014

1.0.3

1.0.3.0

Laravel plugin that helps authenticate with the auth0 service

  Sources   Download

MIT

The Requires

 

by Hernan Rajchert