Download the PHP package maize-tech/laravel-saml2-sp without Composer
On this page you can find all versions of the php package maize-tech/laravel-saml2-sp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maize-tech/laravel-saml2-sp
More information about maize-tech/laravel-saml2-sp
Files in maize-tech/laravel-saml2-sp
Package laravel-saml2-sp
Short Description Laravel Saml2 Service Provider
License MIT
Homepage https://github.com/maize-tech/laravel-saml2-sp
Informations about the package laravel-saml2-sp
Laravel SAML2 Service Provider
This package lets you add SAML2 authentication support within your application.
It acts as a SAML2 Service Provider (SP): it exposes the SP metadata, redirects users to your Identity Provider (IdP) for authentication, consumes the IdP assertion to log the user in, and handles single logout. Under the hood it wraps onelogin/php-saml and stores one or more SAML configurations in the database.
Installation
You can install the package via composer:
You can publish the config and migration files and run the migrations with:
This is the content of the published config file:
Usage
Minimum configuration
After publishing the config file, set at least the following keys in
config/saml2-sp.php (or via your environment):
user_model: the fully qualified class name of your authenticatable user model.login_return_url: where users are redirected after a successful login.logout_return_url: where users are redirected after logout.domain_whitelist: the list of domains accepted as return urls. Anyreturn_url/RelayStatewhose host is not whitelisted falls back to the configured return url. This prevents open-redirect attacks.
Both login_return_url and logout_return_url also accept a closure or the class
name of an invokable class, so you can resolve the destination at runtime:
Creating a SAML configuration
SAML settings are stored in the database through the SamlConfig model. Each row
holds the service provider (sp) and identity provider (idp) sections, merged at
runtime with the default_values defined in the config file. The sp, idp,
security, contactPerson and organization columns are transparently encrypted.
Routes
When routes.enabled is true (the default), the package registers the following
routes under the configured prefix (saml2 by default) and middleware (web):
| Method | URI | Name | Description |
|---|---|---|---|
GET |
saml2/metadata |
saml2.metadata |
Returns the SP metadata XML to share with your IdP. |
GET |
saml2/login |
saml2.login |
Builds the authentication request and redirects to the IdP. |
POST |
saml2/acs |
saml2.acs |
Assertion Consumer Service: consumes the IdP response and logs in. |
GET |
saml2/logout |
saml2.logout |
Builds the logout request and redirects to the IdP. |
GET/POST |
saml2/sls |
saml2.sls |
Single Logout Service: logs the user out and redirects back. |
A typical flow looks like this:
- Share
saml2/metadatawith your Identity Provider. - Send the user to
saml2/login(optionally with a whitelisted?return_url=). They are redirected to the IdP to authenticate. - The IdP posts the assertion back to
saml2/acs. The package validates it, resolves the matching user and logs them in, then redirects to theRelayState(if whitelisted) or tologin_return_url. - To log out, send the user to
saml2/logout. After the IdP processes it, thesaml2/slsendpoint logs the user out locally and redirects tologout_return_url.
You may disable the built-in routes (routes.enabled => false) and register your
own pointing to the package controllers if you need full control.
Events
The package dispatches two events you can listen to:
Maize\Saml2Sp\Events\SamlLoggedIn— after a user is authenticated through the ACS endpoint.Maize\Saml2Sp\Events\SamlLoggedOut— after a user is logged out through the SLS endpoint.
Both expose the affected user via a public $user property:
Customizing the authentication logic
The default AuthenticateUser action looks up the user by matching its email
column against the SAML nameId, then logs it in through the configured guard.
The default LogoutUser action logs out the currently authenticated user.
You can replace either action with your own by pointing the config to a custom class:
A custom authenticate action receives the Maize\Saml2Sp\SamlUserData instance
(name id, attributes and friendly-name attributes) and must return an
Illuminate\Contracts\Auth\Authenticatable:
Resolving the configuration per request (multi-tenant)
By default the DefaultSamlConfigFinder returns the first SamlConfig row. If you
serve several Identity Providers (e.g. one per tenant or domain), implement your
own finder and register it in the config:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Enrico De Lazzari
- Riccardo Dalla Via
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-saml2-sp with dependencies
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/routing Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
onelogin/php-saml Version ^4.3
spatie/laravel-package-tools Version ^1.16
spatie/url Version ^2.2