philwilliammee/samlserviceprovider

A laravel package for SAML 2.0 Service Provider (SP) authentication

dev-main 2022-04-18 16:23 UTC

This package is auto-updated.

Last update: 2024-10-18 21:54:43 UTC


README

Latest Version on Packagist Total Downloads

SAML2.0 Service Provider Laravel Package, use this package to log into a IDP with SAML2.0. Please feel free to contribute to this package. This package has had minimal testing, and provides no security guarantees. Use at your own risk.

Installation

Via Composer

composer require philwilliammee/samlserviceprovider

Usage

Run the migrations

 php artisan migrate

Publish Config and Views with

php artisan vendor:publish --provider="PhilWilliammee\SamlServiceProvider\SamlServiceProviderServiceProvider"

Edit the config file in config/samlserviceprovider.php to your liking.

This package comes with some blade templates that you can use to get you started. You can review them in resources/views/vendor/philwilliammee

example usage:

    <x-samlserviceprovider::login redirect="/user">
        Login
    </x-samlserviceprovider::login>

    <x-samlserviceprovider::logout>
        Logout
    </x-samlserviceprovider::logout>

then in the user controller call:

    $session_id = session()->getId();
    $user_attributes = SamlServiceProvider::getAttributes($session_id);

You will then probably want to login the user with Laravel, something like this:

    $email = $user_attributes['mail'][0];
    $name = $user_attributes['displayName'][0];
    $user = User::where('email', $email)->first();
    if (!$user) {
        $user = User::create([
            'email' => $email,
            'name' => $name,
        ]);
    }
    Auth::login($user);

Change log

Please see the changelog for more information on what has changed recently.

Testing

composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email philwilliammee@gmail.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.