Available in stable development 1.14 1.13 1.12 1.11 1.10 1.9 1.8 1.7 1.6 1.5

Creating authentication sources

All authentication sources are located in the lib/Auth/Source/ directory in a module, and the class name is sspmod_<module>_Auth_Source_<name>. The authentication source must extend the SimpleSAML_Auth_Source class or one of its subclasses.

The "entry point" of an authentication source is the authenticate()-function. Once that function is called, the authentication module can do whatever it wishes to do. There are only two requirements:

Everything else is up to the module. If the module needs to redirect the user, for example because it needs to show the user a page asking for credentials, it needs to save the state array. For that we have the SimpleSAML_Auth_State class. This is only a convenience class, and you are not required to use it (but its use is encouraged, since it handles some potential pitfalls).

1 Saving state

The SimpleSAML_Auth_State class has two functions that you should use: saveState($state, $stage), and loadState($id, $stage). The $stage parameter must be an unique identifier for the current position in the authentication. It is used to prevent a malicious user from taking a state you save in one location, and give it to a different location.

The saveState()-function returns an id, which you should pass to the loadState()-function later.

2 Username/password authentication

Since username/password authentication is quite a common operation, a base class has been created for this. This is the sspmod_core_Auth_UserPassBase class, which is can be found as modules/core/lib/Auth/UserPassBase.php.

The only function you need to implement is the login($username, $password)-function. This function receives the username and password the user entered, and is expected to return the attributes of that user. If the username or password is incorrect, it should throw an error saying so:

throw new SimpleSAML_Error_Error('WRONGUSERPASS');

"Implementing custom username/password authentication" describes how to implement username/password authentication using that base class.

3 Generic rules & requirements