PHPackages                             kchinkesh/laravel-saml - 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. kchinkesh/laravel-saml

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

kchinkesh/laravel-saml
======================

A Laravel Package to Implement SAML based SSO Service Provider

v1.0.0(4y ago)06MITPHPPHP ^8.0

Since Feb 6Pushed 4y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel - Saml
--------------

[](#laravel---saml)

A Laravel package for Saml2 integration as a SP (service provider) based on [OneLogin](https://github.com/onelogin/php-saml) toolkit, which is much lighter and easier to install. It doesn't need separate routes or session storage to work!

The aim of this library is to be as simple as possible. We won't mess with Laravel users, auth, session... We prefer to limit ourselves to a concrete task. Ask the user to authenticate at the IDP and process the response. Same case for SLO requests.

Installation - Composer
-----------------------

[](#installation---composer)

You can install the package via composer:

```
composer require kchinkesh/laravel-saml

```

Then publish the config files with

```
php artisan vendor:publish --tag=saml-config

```

This will add the files `app/config/samlidp_settings.php`, which you will need to customize.

#### Configure laravel-saml to know about IDP

[](#configure-laravel-saml-to-know-about-idp)

```
SAML_IDP_ENTITYID=''
SAML_IDP_SSO_URL=''
SAML_IDP_SLO_URL=''
SAML_IDP_x509=''
```

### Usage

[](#usage)

When you want your user to login, just redirect to the login route configured for the particular IDP, `route('saml_login')`.

Just remember that it does not use any session storage, so if you ask it to login it will redirect to the IDP whether the user is already logged in or not. For example, you can change your authentication middleware.

```
public function handle($request, Closure $next)
{
    if ($this->auth->guest())
    {
        if ($request->ajax())
        {
            return response('Unauthorized.', 401);
        }
        else
        {
            return redirect('saml_login')
        }
    }
    return $next($request);
}
```

After login is called, the user will be redirected to the IDP login page. Then the IDP, which you have configured with an endpoint the library serves, will call back. That will process the response and fire an event when ready. The next step for you is to handle that event. You just need to login the user or refuse.

```
Event::listen(function (\Kchinkesh\LaravelSaml\Events\SamlLoginEvent $event) {
    $user = $event->getSamlUser();
    $userData = [
        'id' => $user->getUserId(),
        'attributes' => $user->getAttributes(),
        'assertion' => $user->getRawSamlAssertion()
    ];
    $laravelUser = User::where('email',$user->getUserId())->first();
    //find user by ID or attribute
    //if it does not exist create it and go on  or show an error message
    Auth::login($laravelUser);
});
```

### Auth persistence

[](#auth-persistence)

Be careful about necessary Laravel middleware for Auth persistence in Session. Add the saml middleware to middleware groups For exemple, it can be:

```
# in App\Http\Kernel
protected $middlewareGroups = [
        'web' => [
            ...
        ],
        'api' => [
            ...
        ],
        'saml' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
        ],
```

### Log out

[](#log-out)

Now there are two ways the user can log out.

- 1 - By logging out in your app: In this case you 'should' notify the IDP first so it closes global session.
- 2 - By logging out of the global SSO Session. In this case the IDP will notify you on /idp/slo endpoint (already provided), if the IDP supports SLO

For case 1, initiate a logout by redirecting the user to the saml2\_logout route (`route('saml_logout')`). Do not close the session immediately as you need to receive a response confirmation from the IDP (redirection). That response will be handled by the library at the `sls` route, and it will fire a `SamlLogoutEvent` event that you can use to complete the logout in the same way as with case 2 below.

For case 2 you will only receive the event. Both cases 1 and 2 receive the same `SamlLogoutEvent` event.

Note that for case 2, you may have to manually save your session to make the logout stick (as the session is saved by middleware, but the OneLogin library will redirect back to your IDP before that happens)

```
Event::listen(function (\Kchinkesh\LaravelSaml\Events\SamlLoginEvent $event) {
    Auth::logout();
    Session::save();
});
```

Note : This Packaged is an Updated Version on aacotroneo/laravel-saml2 which works with PHP 8.0

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1554d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2fb01b639ad01efe80c27b7ccbdb65ae1b0988d46c69648977c147052769163?d=identicon)[chinkesh](/maintainers/chinkesh)

---

Top Contributors

[![kchinkesh](https://avatars.githubusercontent.com/u/25061010?v=4)](https://github.com/kchinkesh "kchinkesh (1 commits)")

### Embed Badge

![Health badge](/badges/kchinkesh-laravel-saml/health.svg)

```
[![Health](https://phpackages.com/badges/kchinkesh-laravel-saml/health.svg)](https://phpackages.com/packages/kchinkesh-laravel-saml)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[olssonm/l5-very-basic-auth

Laravel stateless HTTP basic auth without the need for a database

1662.5M1](/packages/olssonm-l5-very-basic-auth)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)[pschocke/laravel-telegram-login-widget

Easily integrate Telegrams login widget into your Laravel application to send Telegram messages

1610.4k](/packages/pschocke-laravel-telegram-login-widget)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
