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'))
	);

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::instance('simplegroup')->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::instance('simplegroup')->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);

has_access($condition, $driver, $group = null)

The has_access method uses the defined ACL drivers to check the users access according to the given condition.

Static No
Parameters
Param Default Description
$condition required takes a location and the required rights on the location as either a string or an array
$driver required ACL driver to query, or null if all loaded drivers should be called to check for access.
$group null Optionally, only check this group structure, instead of against all defined groups.
Returns boolean, true if access was granted, false if not.
Example
// check if user is allowed to comment
if ( ! Auth::instance('simplegroup')->has_access('comments.create'), null)
{
	Response::redirect('no_admin');
}

// check if user can also update & delete comments
Auth::instance('simplegroup')->has_access('comments.[update,delete]', null);

// call statically (will use the default group driver instance)
Auth::has_access('comments.[update,delete]');

// The same with an array instead of a string
Auth::instance('simplegroup')->has_access(array('comments', array('update', 'delete')), null);

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::check(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::instance('simplegroup')->get_name('admin');