cadoles/phpback-saml

Connecteur SAML pour PHPBack

1.0 2017-01-04 15:49 UTC

This package is not auto-updated.

Last update: 2019-09-15 13:13:34 UTC


README

Connecteur SAML pour PHPBack

Installation

Étape 1: Télécharger le plugin

Cette commande nécessite la présence de composer sur votre système. Les librairies openssl, php5-mcrypt, php5-gettext et php-xml seront également nécessaires au on fonctionnement de ce package.

$ composer require cadoles/phpback-saml
$ composer run-script post-install-cmd -d ./vendor/cadoles/phpback-saml

Étape 2: Activer le plugin

<?php
// application/config/hooks.php

// ...
$hook['post_controller_constructor'][] = array(
    'class'    => 'SAMLHook',
    'function' => 'interceptLogin',
    'filename' => 'SAMLHook.php',
    'filepath' => 'hooks',
    'params'   => array()
);
// ...

Étape 3: Activer la prise en charge des plugins

L'option suivante à modifier dans le fichier de config existe déja, il suffit de changer sa valeur :

<?php
// application/config/config.php

// ...
$config['enable_hooks'] = TRUE;
// ...

Étape 4: Configurer le plugin

<?php
// application/hooks/SAMLConfig.php

// ...
// URL of the DS if you use one, false if not
$config['discoveryService'] = 'https://discovery.renater.fr/test';

// Path to the IPD metadata file. If you use a DS, this file is needed to get the informations for the chosen IDP
$config['metadata_path'] = 'metadata.xml';

// Activate SSO
$config['use_saml_login'] = true;

// Activate SLO
$config['use_saml_logout'] = false;

// Match a local friendly name with the id of the email attribute
$config['email_attribute_id'] = 'eduPersonPrincipalName';

// Match a local friendly name with the id of the givenName attribute
$config['name_attribute_id'] = 'displayName';

$config['saml_settings'] = array (
   // Settings for the PHP-SAML toolkit.
   // See documentation: https://github.com/onelogin/php-saml#settings
   'strict' => true,
   'debug' => false,
   // the IDP part is only used if discoveryService is set to false
   'idp' => array (
        'entityId' => 'http://idp.domain/idp/shibboleth',
        'singleSignOnService' => array (
            'url' => 'http://idp.domain/idp/profile/SAML2/Redirect/SSO',
        ),
        'singleLogoutService' => array (
            'url' => 'http://idp.domain/idp/profile/SAML2/Redirect/SLO',
        ),
        'x509cert' => '',
    ),
   'sp' => array (
        // Entity ID is usually the app root URL
        'entityId' => 'http://app.domain',
        'assertionConsumerService' => array (
            // ACS endpoint, usually root URL + /saml/acs
            'url' => 'http://app.domain/saml/acs',
            'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
        ),
        // You can describe the attributes you want here and make them mandatory
        "attributeConsumingService"=> array(
            "ServiceName" => "SP PHPBack",
            "serviceDescription" => "SP PHPBack",
            "requestedAttributes" => array(
                array(
                    "name" => "eduPersonPrincipalName",
                    "isRequired" => true,
                    "nameFormat" => "",
                    "friendlyName" => "",
                    "attributeValue" => array()
                ),
                array(
                    "name" => "displayName",
                    "isRequired" => true,
                    "nameFormat" => "",
                    "friendlyName" => "",
                    "attributeValue" => array()
                )
            )
        ),
        // SLS endpoint, usually root URL + /saml/sls
        'singleLogoutService' => array (
            'url' => 'http://app.domain/saml/sls',
        ),
        'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
        // Generate your own x509 certificate and private key
        'x509cert' => '',
        'privateKey' => ''
    ),
    // These advanced security parameters should match your federation security requirements
    'security' => array (
        'nameIdEncrypted' => false,
        'authnRequestsSigned' => true,
        'authnRequestsEncrypted' => true,
        'logoutRequestSigned' => true,
        'logoutResponseSigned' => true,
        'signMetadata' => false,
        'wantMessagesSigned' => false,
        'wantAssertionsSigned' => true,
        'wantAssertionsEncrypted' => true,
        'wantNameIdEncrypted' => false,
    )
);
// ...

Mise à jour

$ composer update cadoles/phpback-saml
$ composer run-script post-update-cmd -d ./vendor/cadoles/phpback-saml

Utilisation d'un Discovery Service

Si vous activez l'utilisation d'un Discovery Service, il faut récupérer les metadata des IDP utilisés par le DS. Vous pouvez les récupérer manuellement et indiquer le chemin vers ce fichier dans la configuration du plugin.

Nous mettons également a disposition une librairie PHP permettant de récupérer ce fichier, en vérifiant notamment si la version locale est plus ancienne que la version en ligne. Vous pourrez utiliser cet utilitaire via une tâche CRON sur le serveur afin de vérifier périodiquement si il est nécessaire de rafraîchir les données. Voici la commande à lancer pour récupérer les données de la fédération des crous par exemple :

$ php -r 'include "application/third_party/cadoles/LocalDataMirror.php"; $data = new LocalDataMirror("chemin/metadata.xml", "https://metadata.federation.renater.fr/cnous-crous-h98d/main/main-renater-cnous-crous-metadata.xml"); $data->refreshLocalData();'