PHPackages                             rootinc/laravel-saml2-middleware - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. rootinc/laravel-saml2-middleware

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

rootinc/laravel-saml2-middleware
================================

Saml2 Middleware Auth

0.3.0(4y ago)934.1k↓27%5[1 issues](https://github.com/rootinc/laravel-saml2-middleware/issues)MITPHPPHP &gt;=7.3

Since Aug 31Pushed 4y ago2 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (8)Used By (0)

Laravel Saml2 Middleware
========================

[](#laravel-saml2-middleware)

Provides Saml2 Authentication Middleware for a Laravel App. If you like this, checkout [Laravel Azure Middleware](https://github.com/rootinc/laravel-azure-middleware)

Normal Installation
-------------------

[](#normal-installation)

1. `composer require rootinc/laravel-saml2-middleware`
2. run `php artisan vendor:publish --provider="RootInc\LaravelSaml2Middleware\Saml2ServiceProvider"` to install config file to `config/saml2.php`
3. In our routes folder (most likely `web.php`), add

```
Route::get('/login/saml2', '\RootInc\LaravelSaml2Middleware\Saml2@saml2');
Route::post('/login/saml2callback', '\RootInc\LaravelSaml2Middleware\Saml2@saml2callback');
```

4. In our `App\Http\Kernel.php` add `'saml2' => \RootInc\LaravelSaml2Middleware\Saml2::class,` most likely to the `$routeMiddleware` array.
5. In our `.env` optionally add `SAML2_STRICT, SAML2_SAML2_PROXY_VARS`. If not added, these values will default to true.
6. In our `.env` add `SAML2_IDP_ENTITYID, SAML2_IDP_SSO, SAML2_IDP_SLO and SAML2_IDP_x509`.
7. In our `.env` optionally add `SAML2_SP_NAME_ID_FORMAT, SAML2_SP_ENTITY_ID, SAML2_SP_SSO, SAML2_SP_SLO, SAML2_SP_x509, SAML2_SP_PRIVATE_KEY`. These values are only required to override if the default config does not suffice.
8. In our `App\Http\Middleware\VerifyCsrfToken.php` add `'/login/saml2callback' //original saml2 didn't protect anything.  Since this is a POST for SAML2, the tokens will of course not match.  Thus, we need to ignore` to the `$except` array.
9. Add the `saml2` middleware to your route groups on any routes that needs protected by auth and enjoy 🎉
10. If you need custom callbacks, see [Extended Installation](#extended-installation).

Routing
-------

[](#routing)

`Route::get('/login/saml2', '\RootInc\LaravelSaml2Middleware\Saml2@saml2');` First parameter can be wherever you want to route the saml2 login. \* Change as you would like.

`Route::post('/login/saml2callback', '\RootInc\LaravelSaml2Middleware\Saml2@saml2callback');` First parameter can be whatever you want to route after your callback. \* Change as you would like.

`Route::get('/logout/saml2', '\RootInc\LaravelSaml2Middleware\Saml2@saml2logout');` First parameter can be whatever you want to route after your callback. \* Change as you would like.

`Route::post('/logout/logoutcallback', '\RootInc\LaravelSaml2Middleware\Saml2@logoutcallback');` First parameter can be whatever you want to route after your callback. \* Change as you would like.

- Note - if we change these values, it is important to see [Service Provider Options Override](#service-provider-options-override)

Metadata
--------

[](#metadata)

As of of v0.2.0, we added the ability to get the metadata. Simply add:

`Route::get('/saml2/metadata', '\RootInc\LaravelSaml2Middleware\Saml2@saml2metadata');` First parameter can be whatever you want to route for the metadata. \* Change as you would like.

- Note - if we change these values, it is important to see [Service Provider Options Override](#service-provider-options-override)

Extended Installation
---------------------

[](#extended-installation)

The out-of-the-box implementation let's you login users. However, let's say we would like to store this user into a database, as well as login the user in with Laravel Auth. There are two callbacks that are recommended to extend from the Saml2 class called `success` and `fail`. The following provides information on how to extend the Root Laravel Saml2 Middleware Library:

1. To get started (assuming we've followed the [Normal Installation](#normal-installation) directions), create a file called `AppSaml2.php` in the `App\Http\Middleware` folder. You can either do this through `artisan` or manually.
2. Add this as a starting point in this file:

```
