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.

Auth_Group_Driver

This driver is the base class for all Auth group drivers. It is defined as an abstract class which contains all methods generic to all group drivers, and abstract method definitions for all methods any group driver MUST implement.

Driver configuration

A group driver can load additional drivers that it depends on. Generally, these are ACL drivers. But your implementation could introduce and use custom driver types as well. To do so, add this structure to your driver class:

// autoload the Simpleacl acl driver when loading this group driver
	protected $config = array(
		'drivers' => array('acl' => array('Simpleacl'))
	);

Static interface

For ease of use, the member() method is exposed through the generic Auth static interface.

Using the static interface, you can do

// returns true if the current user is member of group 16.
$is_member = Auth::member(16);

Generic methods

Generic methods are defined in the group base driver, and are available to all Auth group drivers through extension. These methods provide functions to interact with groups, and to check for access.

The methods defined in the classes but not documented here are used internally, and should not be called directly.

get_id()

Returns the drivers unique id. This can be used to identify the driver, or to select a specific driver instance.

Static No
Parameters None
Returns The drivers id string.
Example
// returns 'simpleauth'
$id = Auth::group()->get_id();

set_config($key, $value)

Sets a driver configuration value.

Static No
Parameters
Param Default Description
$key required Configuration key name
$value required Value for this configuration key
Returns void
Example
// set a config value on the simplegroup driver
Auth::group()->set_config('key', 'value');

get_config($key, $default = null)

Gets a driver configuration value.

Static No
Parameters
Param Default Description
$key required Configuration key name
$default null Default value to be returned if the requested key does not exist
Returns mixed
Example
// get a config value of the simplegroup driver, return false if it doesn't exist
$key = Auth::instance('simplegroup')->get_config('key', false);

Abstract methods

Every group driver you develop MUST provide all of these methods, and the MUST return the values documented here.

member($group, $specific = null)

Checks if user is a member of the given group in either all loaded Group drivers or just those specified as the 2nd parameter.

Static Yes
Parameters
Param Default Description
$group required group id
$specific null null to check all or one ore more driver id's (single string or array of strings)
Returns bool, whether one of the (given) drivers had the current user registered as a member
Example
if ( ! Auth::member(100) )
{
	Response::redirect('no_admin');
}

// specific driver
Auth::member(1, 'simplegroup');

// Multiple drivers
Auth::member(0, array('simplegroup', 'genericgroup'));

get_name($group)

Get the display name of the given group name.

Static Yes
Parameters
Param Default Description
$group null name of the group you want to get the display name of
Returns mixed, the retrieved group display name, or false if the given group does not exist.
Example
// get the display name of the admin group
Auth::group()->get_name('admin');