Table of Contents
The purpose of the Authentication component is to provide support for different means of identification and authentication of users using different providers and protocols.
An overview of the most important classes in the Authentication component and this component.
OpenID uses a store to hold the generated nonces and the associations (in "smart" mode). If there is no store specified, then nonces are not checked.
The following example shows how to authenticate against a database.
First, a credentials object is created with username jan.modaal and password 'b1b3773a05c0ed0176787a4f1574ff0075f7521e' (sha1() hash).
An authentication object is created using the credentials object, and a Database filter is added to it. The $database structure specifies the database instance (ezcDbInstance::get()), the table name ('users') and the username and password fields in the table ('user', 'password').
After running the authentication (line 8), if the username and the password do not pass through the Database filter, then the credentials are incorrect and the user must be informed. The getStatus() method is used for this. The values in the status returned must be cycled through and for each value a response is created for the user ("Username incorrect", "Password incorrect").
If run() returned true (line 24) then the user is logged-in and he can see his content.
Any value from the table which holds the users can be fetched. The exact column names must be specified. Example:
// $filter is an ezcAuthenticationDatabaseFilter object $filter->registerFetchData( array( 'name', 'country' ) );
After the authentication process is finished (after run()), retrieve the extra data:
// $filter is an ezcAuthenticationDatabaseFilter object $data = $filter->fetchData();
For the previous example, the $data array will be something like this:
array( 'name' => array( 'John Doe' ), 'country' => array( 'US' ) );
The following example shows how to authenticate against OpenID in "smart" (stateful) mode, using a database store.
A database store is defined at line 25. This store will also hold the nonces which are used to prevent replay attacks.
The database store requires that certain tables are present in the database. To load the .dba definition for these tables into your database you must have the DatabaseSchema component installed. Use the following code to load the schema: