PHPackages                             boldogteam/login - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. boldogteam/login

ActiveLibrary

boldogteam/login
================

Laravel plugin that helps authenticate with the Auth0 service

6.4.0(5y ago)025MITPHPPHP ^7.3 | ^8.0

Since Apr 21Pushed 2y agoCompare

[ Source](https://github.com/boldogteam/laravel-auth0)[ Packagist](https://packagist.org/packages/boldogteam/login)[ RSS](/packages/boldogteam-login/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (52)Used By (0)

Laravel Auth0 Plugin
====================

[](#laravel-auth0-plugin)

[![CircleCI](https://camo.githubusercontent.com/6e9bb9c9030dd39e726f26b535dc5838fb96d20fce7d18141877cd3df199781f/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f70726f6a6563742f6769746875622f61757468302f6c61726176656c2d61757468302f6d61737465722e737667)](https://circleci.com/gh/auth0/laravel-auth0)[![Latest Stable Version](https://camo.githubusercontent.com/a1f4de4d59c0a951a9a282fc847931142580e4976c1bb749c9001408bb83b351/68747470733a2f2f706f7365722e707567782e6f72672f61757468302f6c6f67696e2f762f737461626c65)](https://packagist.org/packages/auth0/login)[![License](https://camo.githubusercontent.com/81ea1ea07b20e1a8868f724778b658988e03ee96e515c1fc0b091b23d454b28a/68747470733a2f2f706f7365722e707567782e6f72672f61757468302f6c6f67696e2f6c6963656e7365)](https://packagist.org/packages/auth0/login)[![Total Downloads](https://camo.githubusercontent.com/e2e2d347837863fcb44ce3cc5eb14358066c1872ce5636d5577a68950e39fe21/68747470733a2f2f706f7365722e707567782e6f72672f61757468302f6c6f67696e2f646f776e6c6f616473)](https://packagist.org/packages/auth0/login)[![FOSSA Status](https://camo.githubusercontent.com/1d126433e2a536290693efde53c313aec73c918726797f2f9336804f3b9149b8/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d25324661757468302532466c61726176656c2d61757468302e7376673f747970653d736869656c64)](https://app.fossa.com/projects/git%2Bgithub.com%2Fauth0%2Flaravel-auth0?ref=badge_shield)

This plugin helps you integrate your [Laravel](https://laravel.com/) WebApp with [Auth0](https://auth0.com/) to achieve Single Sign On with a few simple steps.

Supported Framework Versions
----------------------------

[](#supported-framework-versions)

Our plugin maintains support for [all actively supported versions](https://laravel.com/docs/8.x/releases#support-policy) of the Laravel framework, including [6.X (LTS)](https://laravel.com/docs/8.x/releases), [7.X](https://laravel.com/docs/7.x/releases) and [8.X](https://laravel.com/docs/8.x/releases).

Past releases of our plugin may potentially run on earlier, now unsupported versions of the Laravel framework, but these releases are not maintained. The final release of our plugin to support the Laravel 5.X series was 6.1.0.

Documentation
-------------

[](#documentation)

Please see the [Laravel webapp quickstart](https://auth0.com/docs/quickstart/webapp/laravel) for a complete guide on how to install this in an existing project or to download a pre-configured sample project. Additional documentation on specific scenarios is below.

### Setting up a JWKs cache

[](#setting-up-a-jwks-cache)

In the `register` method of your `AppServiceProvider` add:

```
// app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Cache;
// ...
    public function register()
    {
        // ...
        $this->app->bind(
            '\Auth0\SDK\Helpers\Cache\CacheHandler',
            function() {
                static $cacheWrapper = null;
                if ($cacheWrapper === null) {
                $cache = Cache::store();
                $cacheWrapper = new LaravelCacheWrapper($cache);
            }
            return $cacheWrapper;
        });
    }
```

You can implement your own cache strategy by creating a new class that implements the `Auth0\SDK\Helpers\Cache\CacheHandler` contract, or just use the cache strategy you want by picking that store with `Cache::store('your_store_name')`;

### Storing users in your database

[](#storing-users-in-your-database)

You can customize the way you handle the users in your application by creating your own `UserRepository`. This class should implement the `Auth0\Login\Contract\Auth0UserRepository` contract. Please see the [Custom User Handling section of the Laravel Quickstart](https://auth0.com/docs/quickstart/webapp/laravel#optional-custom-user-handling) for the latest example.

### Using auth guard

[](#using-auth-guard)

To protect APIs using an access token generated by Auth0, there is an `auth0` API guard provided ([Laravel documentation on guards](https://laravel.com/docs/7.x/authentication#adding-custom-guards)). To use this guard, add it to `config/auth.php` with the driver `auth0`:

```
'guards' => [
    ...
    'auth0' => [
        'driver' => 'auth0',
        'provider' => 'auth0',
    ],
],

'providers' => [
    ...
    'auth0' => [
        'driver' => 'auth0',
    ],
],

```

Once that has been added, add the guard to the middleware of any API route and check authentication during the request:

```
// get user
auth('auth0')->user();
// check if logged in
auth('auth0')->check();
// protect routes via middleware use
Route::group(['middleware' => 'auth:auth0'], function () {});

```

Examples
--------

[](#examples)

### Organizations (Closed Beta)

[](#organizations-closed-beta)

Organizations is a set of features that provide better support for developers who build and maintain SaaS and Business-to-Business (B2B) applications.

Using Organizations, you can:

- Represent teams, business customers, partner companies, or any logical grouping of users that should have different ways of accessing your applications, as organizations.
- Manage their membership in a variety of ways, including user invitation.
- Configure branded, federated login flows for each organization.
- Implement role-based access control, such that users can have different roles when authenticating in the context of different organizations.
- Build administration capabilities into your products, using Organizations APIs, so that those businesses can manage their own organizations.

Note that Organizations is currently only available to customers on our Enterprise and Startup subscription plans.

#### Logging in with an Organization

[](#logging-in-with-an-organization)

Open your Auth0 Laravel plugin configuration file (usually `config/laravel-auth0.php`) uncomment the `organization` optiion and specify the Id for your Organization (found in your Organization settings on the Auth0 Dashboard.)

```
// config/laravel-auth0.php
// ...

/*
|--------------------------------------------------------------------------
|   Auth0 Organizations
|--------------------------------------------------------------------------
|   organization (string) Optional. Id of an Organization, if being used. Used when generating log in urls and validating token claims.
*/

'organization' => 'org_E6WbrPMQU2UJn6Rz',
```

From there, the Organization will automatically be used throughout your Laravel application's authentication login, including redirecting to the Universal Login page.

```
// Expects the Laravel plugin to be configured first, as demonstrated above.

App::make('auth0')->login();
```

#### Accepting user invitations

[](#accepting-user-invitations)

Auth0 Organizations allow users to be invited using emailed links, which will direct a user back to your application. The URL the user will arrive at is based on your configured `Application Login URI`, which you can change from your Application's settings inside the Auth0 dashboard.

When the user arrives at your application using an invite link, you can expect three query parameters to be provided: `invitation`, `organization`, and `organization_name`. These will always be delivered using a GET request.

A helper function is provided to handle extracting these query parameters and automatically redirecting to the Universal Login page. Invoke this from your application's logic, such as a controller for an authentication route, to handle this process automatically.

```
// routes/example.php

Route::get('/invite', [ExampleIndexController::class, 'invite'])->name('invite');
```

```
// Http/Controllers/Example/ExampleIndexController.php
