PHP code example of helsingborg-stad / sso-saml

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

    

helsingborg-stad / sso-saml example snippets


SAML_ATTRIBUTES_MAPPING = [
    'username' => 'http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname',
    'first-name' => 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname',
    'last-name' => 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname',
    'email' => 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress',
    'ad-groups' => 'http://schemas.xmlsoap.org/claims/Group',
];

SAML_MAP_TO_AD_GROUP = true;

SAML_AD_GROUP_ROLE_MAPPING = [
    'Domain Users' => 'subscriber',
    'Domain Admins' => 'administrator'
];

if (class_exists('\SAMLSSO\Client')) {
    $client = new \SAMLSSO\Client();
    // Supply where to redirect after login.
    $client->authenticate('https://www.example.com/redirect');
}

// NOTE Never place certificates below the root web folder!
$idpCertificateFile = '/etc/certs/idp-cert.cer';
$spCertificateFile = '/etc/certs/sp-cert.cer';
$spCertificateKeyFile = '/etc/certs/sp-cert.key';

define('SAML_SP_ENITITY_ID', 'https://www.example.com/saml/metadata');
define('SAML_SP_ACS_URL', 'https://www.example.com/saml/acs');
define('SAML_IDP_ENTITY_ID', 'https://www.example.com/adfs/services/trust');
define('SAML_IDP_SSO_URL', 'https://www.example.com/adfs/ls/');
define('SAML_IDP_SLS_URL', 'https://www.example.com/adfs/ls/');

if (file_exists($idpCertificateFile)) {
    define('SAML_IDP_CERTIFICATE', file_get_contents($idpCertificateFile));
}

if (file_exists($spCertificateFile)) {
    define('SAML_SP_CERTIFICATE', file_get_contents($spCertificateFile));
}

if (file_exists($spCertificateKeyFile)) {
    define('SAML_SP_CERTIFICATE_KEY', file_get_contents($spCertificateKeyFile));
}