PHP code example of kn4ppster / laravel4-saml2

1. Go to this page and download the library: Download kn4ppster/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/ */

    

kn4ppster / laravel4-saml2 example snippets


'providers' => array(
    		'Kn4ppster\Saml2\Saml2ServiceProvider',
)

$metadata['http://laravel_url/saml/metadata'] = array(
    'AssertionConsumerService' => 'http://laravel_url/saml/acs',
    'SingleLogoutService' => 'http://laravel_url/saml/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 SAML2::login(URL::full()); //url is saved in RelayState
		
	}
});


Event::listen('saml2.loginRequestReceived', function(Saml2User $user)
{
    //$user->getAttributes();
    //$user->getUserId();
    //base64_decode($user->getRawSamlAssertion();
    $laravelUser = //find user by ID or attribute
    //if it does not exist create it and go on  or show an error message
    Auth::login($laravelUser);
});

Event::listen('saml2.logoutRequestReceived', function()
{
    Auth::logout();
    //echo "bye, we logged out.";
});