Auth パッケージ
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.
Interface
The Auth class provides a static interface for generic methods, and contains a __callStatic magic method
which allows you to fetch loaded driver instances, and call driver methods statically (only if multiple
concurrent drivers are disabled in the auth config!).
forge($custom = array())
Instantiates the Auth driver or drivers defined in the Auth configuration file. Optionally, you can pass
a custom configuration array to define the driver that needs to be instantiated.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$custom |
mixed |
Driver configuration array, or string containing the driver name to instantiate. If not given, the values from the Auth config file are used. |
|
返り値 |
Auth_Login_Driver instance |
例外 |
AuthException, if the defined driver failed to load, or if another drivers is already instantiated using the same driver id. |
例 |
// Create the default instance(s)
Auth::forge();
// Create the SimpleAuth instance
Auth::forge('simpleauth');
// or specify multiple driver settings
Auth::forge(array('driver' => 'simpleauth', 'id' => 'customid'));
|
If you only use a single Auth driver configured in the Auth configuration file, you don't need to call this method manually.
The default instance will be created automatically the first time the default instance is requested by one of the other methods.
instance($instance = null)
Retrieves a loaded driver instance. When multiple drivers are set in config the first driver loaded will
be set as the default driver.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$instance |
null |
null to fetch the default driver, or a driver id to get a specific one |
|
返り値 |
Auth_Login_Driver |
例 |
// Logout the default driver
Auth::instance()->logout();
// Login the SimpleAuth driver
Auth::instance('simpleauth')->login(Input::post('username'), Input::post('password'));
|
If the default instance is requested, but none is loaded, instance() will call forge() to create the
default instance based on the settings defined in the Auth configuration file.
unload($driver_id = null)
Removes a loaded driver instance. If null, the default driver instance will be removed.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$driver_id |
null |
null to remove the default driver, or a driver id to remove a specific one |
|
返り値 |
boolean, true if the unload succeeded, false otherwise. |
例外 |
AuthException, when $driver_id is not a valid driver. |
例 |
// Remove the default driver
Auth::unload();
// Remove the SimpleAuth driver
Auth::unload('simpleauth');
|
check($specific = null)
Checks either all loaded Login drivers or just those specified as the parameter.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$specific |
null |
null to check all or one ore more driver id's (single string or array of strings) |
|
返り値 |
bool, whether one of the (given) drivers successfully validated the login |
例 |
if ( ! Auth::check())
{
Response::redirect('login');
}
// specific driver
Auth::check('simpleauth');
// Multiple drivers
Auth::check(array('simpleauth', 'twitter'));
|
verified($specific = null)
Get a specific verified driver or all verified drivers.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$specific |
null |
null to return all verified drivers in an array, or one specific driver id |
|
返り値 |
Array|Auth_Login_Driver|false. When |
例 |
// check if the simpleauth driver is verified
$driver = Auth::verified('simpleauth');
|
logout()
Logout of all currently logged in drivers.
register_driver_type($type, $check_method)
Registers a new driver type.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$type |
required |
Type of Auth driver to be registered. |
$check_method |
required |
The driver method to be called when verifying drivers of this type. |
|
例 |
// register the 'role' driver type
if ( ! Auth::register_driver_type('role', 'check_role'))
{
throw new AuthException('role could not be registered');
}
|
Both type and method must be unique amongst all registered drivers. This method returns 'false' if this is not the case.
unregister_driver_type($type)
Unregisters a driver type.
Static |
Yes |
パラメータ |
パラメータ |
規定値 |
説明 |
$type |
required |
Type of Auth driver to be removed. |
|
例 |
// remove the 'role' driver type
Auth::unregister_driver_type('role');
|
Note that the default drivers types, 'login', 'group' and 'acl' can not be unregistered!