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_Acl_Driver

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

Static interface

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

Using the static interface, you can do

// returns true if the current user has the required permissions
$may_access_comments = Auth::has_access('comments[read,write]');

Generic methods

Generic methods are defined in the acl base driver, and are available to all Auth acl drivers through extension. These methods provide functions to interact with specific acls, 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 'simpleacl'
$id = Auth::acl()->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 simpleacl driver
Auth::acl()->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 simpleacl driver, return false if it doesn't exist
$key = Auth::instance('simpleacl')->get_config('key', false);

Abstract methods

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

has_access($condition, Array $entity)

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
$entity required user or group identifier in the form of array(driver_id, id).
Returns boolean, true if access was granted, false if not.
Example
// check if user is allowed to comment
if ( ! Auth::acl()->has_access('comments.create'), array('simplegroup', 1))
{
	Response::redirect('no_admin');
}