### SSO-Friendly Link Example Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Example of a generated URL that initiates the SSO login process and redirects to the intended destination. ```text https://yourdomain/saml/63fffdd1-f416-4bed-b3db-967b6a56896b/login?returnTo=https://yourdomain.com/your/actual/link ``` -------------------------------- ### Install package via composer Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Install the package into your Laravel project. ```bash composer require scaler-tech/laravel-saml2 ``` -------------------------------- ### Tenant Creation Output Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md The expected output after successfully running the tenant creation command. ```text The tenant #1 (63fffdd1-f416-4bed-b3db-967b6a56896b) was successfully created. Credentials for the tenant -------------------------- Identifier (Entity ID): https://yourdomain.com/saml/63fffdd1-f416-4bed-b3db-967b6a56896b/metadata Reply URL (Assertion Consumer Service URL): https://yourdomain.com/saml/63fffdd1-f416-4bed-b3db-967b6a56896b/acs Sign on URL: https://yourdomain.com/saml/63fffdd1-f416-4bed-b3db-967b6a56896b/login Logout URL: https://yourdomain.com/saml/63fffdd1-f416-4bed-b3db-967b6a56896b/logout Relay State: / (optional) ``` -------------------------------- ### Run database migrations Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Execute migrations to set up the necessary tables for tenant management. ```bash php artisan migrate ``` -------------------------------- ### Create a SAML2 Tenant Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Use the artisan command to register a new tenant with Azure AD credentials. ```bash php artisan saml2:create-tenant \ --key=azure_testing \ --entityId=https://sts.windows.net/fb536a7a-7251-4895-a09a-abd8e614c70b/ \ --loginUrl=https://login.microsoftonline.com/fb536a7a-7251-4895-a09a-abd8e614c70b/saml2 \ --logoutUrl=https://login.microsoftonline.com/common/wsfederation?wa=wsignout1.0 \ --x509cert="MIIC0jCCAbqgAw...CapVR4ncDVjvbq+/S" \ --metadata="customer:11235,anotherfield:value" // you might add some customer parameters here to simplify logging in your customer afterwards ``` -------------------------------- ### Publish configuration file Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Publish the package configuration to the application config directory. ```bash php artisan vendor:publish --provider="Slides\Saml2\ServiceProvider" ``` -------------------------------- ### Run PHPUnit Tests Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Execute the test suite from the package root directory. ```bash vendor/bin/phpunit ``` -------------------------------- ### Configure SAML Middleware Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Define the middleware prefix in the configuration file and register the necessary middleware group in the Kernel. ```php /* |-------------------------------------------------------------------------- | Built-in routes prefix |-------------------------------------------------------------------------- | | Here you may define the prefix for built-in routes. | |*/ 'routesMiddleware' => ['saml'], ``` ```php protected $middlewareGroups = [ 'web' => [ ... ], 'api' => [ ... ], 'saml' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, ], ``` -------------------------------- ### Handle SAML Authentication Events Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Listen for SignedIn events to retrieve user data and authenticate the user within the application. Ensure replay attack prevention by tracking message IDs. ```php Event::listen(\Slides\Saml2\Events\SignedIn::class, function (\Slides\Saml2\Events\SignedIn $event) { $messageId = $event->getAuth()->getLastMessageId(); // your own code preventing reuse of a $messageId to stop replay attacks $samlUser = $event->getSaml2User(); $userData = [ 'id' => $samlUser->getUserId(), 'attributes' => $samlUser->getAttributes(), 'assertion' => $samlUser->getRawSamlAssertion() ]; $user = // find user by ID or attribute // Login a user. Auth::login($user); }); ``` -------------------------------- ### Configure Nginx for ngrok Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Override host headers in Nginx to support local testing via ngrok. ```nginx fastcgi_param HTTP_HOST your.ngrok.io; fastcgi_param HTTPS on; ``` -------------------------------- ### Register service provider and alias Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Manual registration for Laravel versions older than 5.5 in config/app.php. ```php 'providers' => [ ... Slides\Saml2\ServiceProvider::class, ] 'alias' => [ ... 'Saml2' => Slides\Saml2\Facades\Auth::class, ] ``` -------------------------------- ### Migrate composer.json dependencies Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Update the package requirement from the archived version to the current scaler-tech version. ```json { "require": { "24slides/laravel-saml2": "^2.0" } } ``` ```json { "require": { "scaler-tech/laravel-saml2": "^2.5" } } ``` -------------------------------- ### Handle Logout Events Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Listen for the SignedOut event to perform application-level logout and ensure the session is saved before redirection. ```php Event::listen('Slides\Saml2\Events\SignedOut', function (SignedOut $event) { Auth::logout(); Session::save(); }); ``` -------------------------------- ### Update composer dependencies Source: https://github.com/scaler-tech/laravel-saml2/blob/master/README.md Run this command to update the package and its dependencies after modifying composer.json. ```bash composer update scaler-tech/laravel-saml2 --with-all-dependencies ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.