Download the PHP package 24slides/laravel-saml2 without Composer
On this page you can find all versions of the php package 24slides/laravel-saml2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-saml2
[Laravel 5.4+] SAML Service Provider
An integration to add SSO to your service via SAML2 protocol based on OneLogin toolkit.
This package turns your application into Service Provider with the support of multiple Identity Providers.
Requirements
- Laravel 5.4+
- PHP 7.0+
Getting Started
Installing
Step 1. Install dependency
If you are using Laravel 5.5 and higher, the service provider will be automatically registered.
For older versions, you have to add the service provider and alias to your config/app.php
:
Step 2. Publish the configuration file.
Step 3. Run migrations
Configuring
Once you publish saml2.php
to app/config
, you need to configure your SP. Most of options are inherited from OneLogin Toolkit, so you can check documentation there.
Identity Providers (IdPs)
To distinguish between identity providers there is an entity called Tenant that represent each IdP.
When request comes to an application, the middleware parses UUID and resolves the Tenant.
You can easily manage tenants using the following console commands:
artisan saml2:create-tenant
artisan saml2:update-tenant
artisan saml2:delete-tenant
artisan saml2:restore-tenant
artisan saml2:list-tenants
artisan saml2:tenant-credentials
To learn their options, run a command with
-h
parameter.
Each Tenant has the following attributes:
- UUID — a unique identifier that allows to resolve a tenannt and configure SP correspondingly
- Key — a custom key to use for application needs
- Entity ID — Identity Provider Entity ID
- Login URL — Identity Provider Single Sign On URL
- Logout URL — Identity Provider Logout URL
- x509 certificate — The certificate provided by Identity Provider in base64 format
- Metadata — Custom parameters for your application needs
Default routes
The following routes are registered by default:
GET saml2/{uuid}/login
GET saml2/{uuid}/logout
GET saml2/{uuid}/metadata
POST saml2/{uuid}/acs
POST saml2/{uuid}/sls
You may disable them by setting saml2.useRoutes
to false
.
/saml2
prefix can be changed viasaml2.routesPrefix
config parameter.
Usage
Authentication events
The simplest way to handle SAML authentication is to add listeners on Slides\Saml2\SignedIn
and Slides\Saml2\SignedOut
events.
Middleware
To define a middleware for default routes, add its name to config/saml2.php
:
Then you need to define necessary middlewares for your group in app/Http/Kernel.php
:
Logging out
There are two ways the user can logout:
- By logging out in your app. In this case you SHOULD notify the IdP first so it'll close the global session.
- By logging out of the global SSO Session. In this case the IdP will notify you on
/saml2/{uuid}/slo
endpoint (already provided).
For the first case, call Saml2Auth::logout();
or redirect the user to the route saml.logout
which does just that.
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 /saml2/sls
and will fire an event for you to complete the operation.
For the second case you will only receive the event. Both cases receive the same event.
Note that for the second case, 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):
SSO-friendly links
Sometimes, you need to create links to your application with support of SSO lifecycle. It means you expect a user to be signed in once you click on that link.
The most popular example is generating links from emails, where you need to make sure when user goes to your application from email, he will be logged in.
To solve this issue, you can use helpers that allow you create SSO-friendly routes and URLs — saml_url()
and saml_route()
.
To generate a link, you need to call one of functions and pass UUID of the tenant as a second parameter, unless your session knows that user was resolved by SSO.
To retrieve UUID based on user, you should implement logic that links your internal user to a tenant.
Then, it generates a link like this:
Basically, when user clicks on a link, it initiates SSO login process and redirects it back to your needed URL.
Examples
Azure AD
At this point, we assume you have an application on Azure AD that supports Single Sign On.
Step 1. Retrieve Identity Provider credentials
You need to retrieve the following parameters:
- Login URL
- Azure AD Identifier
- Logout URL
- Certificate (Base64)
Step 2. Create a Tenant
Based on information you received below, create a Tenant, like this:
Once you successfully created the tenant, you will receive the following output:
Step 3. Configure Identity Provider
Using the output below, assign parameters to your IdP on application Single-Sign-On settings page.
Step 4. Make sure your application accessible by Azure AD
Test your application directly from Azure AD and make sure it's accessible worldwide.
Running locally
If you want to test it locally, you may use ngrok.
In case if you have a problem with URL creation in your application, you can overwrite host header in your nginx host config file by adding the following parameters:
Replace
your.ngrok.io
with your actual ngrok URL
Tests
Run the following in the package folder:
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- aacotroneo
- brezzhnev
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-saml2 with dependencies
ext-openssl Version *
illuminate/console Version ~5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/database Version ~5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/support Version ~5.4|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
onelogin/php-saml Version ^3.0|^4.0
ramsey/uuid Version ^3.8|^4.0