Class BasicAuthenticate
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. Clients using Basic Authentication must support cookies. Since AuthComponent identifies users based on Session contents, clients using Basic Auth must support cookies.
Using Basic auth
In your controller's components array, add auth + the required settings. {{{ public $components = array( 'Auth' => array( 'authenticate' => array('Basic') ) ); }}}
In your login function just call $this->Auth->login()
without any checks for POST data. This
will send the authentication headers, and trigger the login dialog in the browser/client.
- BaseAuthenticate
- BasicAuthenticate
Direct Subclasses
Since: 2.0
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Controller/Component/Auth/BasicAuthenticate.php
Inherited Properties
Method Summary
-
__construct() public
Constructor, completes configuration for basic authentication. -
authenticate() public
Authenticate a user using HTTP auth. Will use the configured User model and attempt a login using HTTP auth.
-
getUser() public
Get a user based on information in the request. Used by cookie-less auth for stateless clients. -
loginHeaders() public
Generate the login headers -
unauthenticated() public
Handles an unauthenticated access attempt by sending appropriate login headers
Method Detail
__construct() public ¶
__construct( ComponentCollection
$collection , array $settings )
Constructor, completes configuration for basic authentication.
Parameters
-
ComponentCollection
$collection - The Component collection used on this request.
- array $settings
- An array of settings.
Overrides
authenticate() public ¶
authenticate( CakeRequest
$request , CakeResponse
$response )
Authenticate a user using HTTP auth. Will use the configured User model and attempt a login using HTTP auth.
Parameters
-
CakeRequest
$request - The request to authenticate with.
-
CakeResponse
$response - The response to add headers to.
Returns
Either false on failure, or an array of user data on success.
getUser() public ¶
getUser( CakeRequest
$request )
Get a user based on information in the request. Used by cookie-less auth for stateless clients.
Parameters
-
CakeRequest
$request - Request object.
Returns
Either false or an array of user information
Overrides
loginHeaders() public ¶
loginHeaders( )
Generate the login headers
Returns
Headers for logging in.
unauthenticated() public ¶
unauthenticated( CakeRequest
$request , CakeResponse
$response )
Handles an unauthenticated access attempt by sending appropriate login headers
Parameters
-
CakeRequest
$request - A request object.
-
CakeResponse
$response - A response object.
Throws
Overrides
Methods inherited from BaseAuthenticate
_findUser() protected ¶
_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.
Parameters
- string|array $username
- The username/identifier, or an array of find conditions.
- string $password optional null
- The password, only used if $username param is string.
Returns
Either false on failure, or an array of user data.
_password() protected deprecated ¶
_password( string $password )
Hash the plain text password so that it matches the hashed/encrypted password in the datasource.
Deprecated
Parameters
- string $password
- The plain text password.
Returns
The hashed form of the password.
logout() public ¶
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.
Parameters
- array $user
- The user about to be logged out.