Basic Authentication adapter for AuthComponent.
Provides Basic HTTP authentication support for AuthComponent. Basic Auth will authenticate users against the configured userModel and verify the username and passwords match.
In your controller's components array, add auth + the required settings.
public $components = array( 'Auth' => array( 'authenticate' => array('Basic') ) );
You should also set AuthComponent::$sessionKey = false; in your AppController's beforeFilter() to prevent CakePHP from sending a session cookie to the client.
Since HTTP Basic Authentication is stateless you don't need a login() action in your controller. The user credentials will be checked on each request. If valid credentials are not provided, required authentication headers will be sent by this authentication provider which triggers the login dialog in the browser/client.
You may also want to use $this->Auth->unauthorizedRedirect = false;. By default, unauthorized users are redirected to the referrer URL, AuthComponent::$loginAction, or '/'. If unauthorizedRedirect is set to false, a ForbiddenException exception is thrown instead of redirecting.
BasicAuthenticate __construct( ComponentCollection $collection , array $settings )
Constructor, completes configuration for basic authentication.
ComponentCollection $collection $settings BaseAuthenticate::__construct() authenticate( CakeRequest $request , CakeResponse $response )
Authenticate a user using HTTP auth. Will use the configured User model and attempt a login using HTTP auth.
CakeRequest $request CakeResponse $response mixedgetUser( CakeRequest $request )
Get a user based on information in the request. Used by cookie-less auth for stateless clients.
CakeRequest $request mixedBaseAuthenticate::getUser() loginHeaders( )
Generate the login headers
stringunauthenticated( CakeRequest $request , CakeResponse $response )
Handles an unauthenticated access attempt by sending appropriate login headers
CakeRequest $request CakeResponse $response UnauthorizedExceptionBaseAuthenticate::unauthenticated() _findUser( string|array $username , string $password null )
Find a user record using the standard options.
The $username parameter can be a (string)username or an array containing conditions for Model::find('first'). If the $password param is not provided the password field will be present in returned array.
Input passwords will be hashed even when a user doesn't exist. This helps mitigate timing attacks that are attempting to find valid usernames.
$username $password optional null boolean|array_password( string $password )
Hash the plain text password so that it matches the hashed/encrypted password in the datasource.
$password stringimplementedEvents( )
Implemented events
arrayCakeEventListener::implementedEvents() logout( array $user )
Allows you to hook into AuthComponent::logout(), and implement specialized logout behavior.
All attached authentication objects will have this method called when a user logs out.
$user passwordHasher( )
Return password hasher object
AbstractPasswordHasherCakeException protected ComponentCollection
A Component collection, used to get more components.
public array
Settings for this object.
fields The fields to use to identify a user by.userModel The model name of the User, defaults to User.userFields Array of fields to retrieve from User model, null to retrieve all. Defaults to null.scope Additional conditions to use when looking up and authenticating users, i.e. array('User.is_active' => 1).
recursive The value of the recursive key passed to find(). Defaults to 0.contain Extra models to contain and store in session.passwordHasher Password hasher class. Can be a string specifying class name or an array containing className key, any other keys will be passed as settings to the class. Defaults to 'Simple'.array( 'fields' => array( 'username' => 'username', 'password' => 'password' ), 'userModel' => 'User', 'userFields' => null, 'scope' => array(), 'recursive' => 0, 'contain' => null, 'passwordHasher' => 'Simple' )
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-BasicAuthenticate.html