Auth package

The Auth package provides a standardized interface for authentication in Fuel. This allows our users to write their own drivers and easily integrate a new driver to work with old code by keeping the basic methods consistent.

Writing your own drivers

Writing drivers can be done in two ways. Either by extending the Auth driver classes to create a new driver from scratch or extending the SimpleAuth classes and changing them where needed.

An Auth driver consists of three types of classes working together. These are:

  • Login (Auth_Login_Driver).
  • Group (Auth_Group_Driver).
  • Acl (Auth_Acl_Driver).

Extending auth classes

Extend these classes like so:


class Auth_Login_MyDriver extends \Auth\Auth_Login_Driver

	// Implement all the needed functions and variables defined in the driver class.


/* End of file mydriver.php */

Implementing functions

When extending the Auth driver classes take note on the expected return values of each function that needs to be implemented. Every method supplies an example so you know what needs to be returned. Here is an example:

 * Get User Identifier of the current logged in user
 * in the form: array(driver_id, user_id)
 * @return  array
abstract public function get_user_id();

The code above show you the get_user_id function that every driver should have. Like in all classes you extend that have abstract functions, these functions must be defined in the extended class. The return type of this function is provided in the comment, in this case array(driver_id, user_id). In order to get your driver to work alongside other drivers make sure you return the right values or your driver breaks protocol.

Here is that same function but then the implementation from the SimpleAuth driver.

 * Get the user's ID
 * @return  Array  containing this driver's ID & the user's ID
public function get_user_id()
	if (empty($this->user))
		return false;

	return array($this->id, (int) $this->user['id']);

Once you have everything in place for the new driver. Replace or add it to the auth config.

// Inside config/auth.php array

// Add it as a driver
'driver' => array('SimpleAuth', 'MyDriver'),

// or replace the SimpleAuth driver
'driver' => array('MyDriver'),