1. Go to this page and download the library: Download pitbulk/laravel4-saml2 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$metadata['http://laravel_url/saml2/metadata'] = array(
'AssertionConsumerService' => 'http://laravel_url/saml2/acs',
'SingleLogoutService' => 'http://laravel_url/saml2/sls',
//the following two affect what the $Saml2user->getUserId() will return
'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
'simplesaml.nameidattribute' => 'uid'
);
Route::filter('auth', function()
{
if (Auth::guest()) {
return Saml2Auth::login(URL::full()); // The users intended URL is saved in RelayState
}
});
Event::listen('saml2.loginRequestReceived', function(Saml2User $saml2User)
{
// Useful data in $saml2User:
// $saml2User->getAttributes();
// $saml2User->getUserId();
// base64_decode($saml2User->getRawSamlAssertion());
// $saml2User->getIntendedUrl()
// Find user by ID or attribute
$user = User::find($samlUser->getUserId);
$user = User::where('email', $samlUser->getNameId());
if(!$user) {
// If the user does not exist, create a new one just in time, or show an error message
}
// Create the login session for the user
Auth::login($user);
});
Event::listen('saml2.logoutRequestReceived', function()
{
Auth::logout();
//echo "bye, we logged out.";
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.