Skip to the content
Documentation

Single Sign On (SSO) handlers

No ratings yet

A single sign-on (SSO) handler signs a visitor in automatically, without the login form, when another system has already identified them: for example a trusted header set by a corporate proxy, or a cookie of a central login service.

How it works

For a visitor who is not signed in and has not just signed out, Exponential calls every handler listed in site.ini [UserSettings] SingleSignOnHandlerArray, in order. A handler returns an eZUser to sign in, or false. The first user returned is signed in, the session is updated, and the same address is loaded again with a redirect (HTTP 302).

The class of a handler named My must be eZMySSOHandler: the prefix eZ and the suffix SSOHandler are added to the name. A class that cannot be loaded is reported in the debug output as "Undefined ssoHandler class".

Writing a handler

In an extension, for example mysso:

# extension/mysso/settings/site.ini.append.php
[UserSettings]
SingleSignOnHandlerArray[]=My
<?php
// extension/mysso/classes/ezmyssohandler.php
class eZMySSOHandler
{
    /**
     * @return eZUser|false the user to sign in, or false
     */
    public function handleSSOLogin()
    {
        // example: a login passed on by a trusted reverse proxy
        $login = $_SERVER['HTTP_X_REMOTE_USER'] ?? '';
        if ( $login === '' )
            return false;
        $user = eZUser::fetchByName( $login );
        return ( $user instanceof eZUser && $user->isEnabled() ) ? $user : false;
    }
}

Activate the extension, regenerate the autoloads (php bin/php/ezpgenerateautoloads.php -e), clear the INI cache, and with Exponential Velocity restart it.

Limits and security

  • A handler runs on every request of a visitor who is not signed in. Keep it fast, and enable it only in the siteaccesses that need it (a siteaccess override instead of the extension's global setting).
  • Whatever the handler trusts decides who is signed in. Trust a header only when every request passes through the proxy that sets it.

Related pages

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.