Adapter
Adapter
Properties
options
protected Map $options
public $
identity
public string $identity
credential
public string $credential
extra
Extra data fields to store from the user record.
protected array $extra
noCredentialHashing
private bool $noCredentialHashing
Methods
__construct
Construct the adapter.
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$config | Map | The configuration options |
setIdentity
Sets the identity for the authentication adapter.
public setIdentity({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$identity | string | the identity to be set |
setCredential
Sets the credential for authentication.
public setCredential({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$credential | string | the credential to be set |
getIdentity
Retrieves the identity of the current user.
public getIdentity({Array})
getCredentialHash
Get the encrypted hash of a credential/password.
public getCredentialHash({Array})
This method uses the "encryption" options from the application configuration to generate a password hash based on the supplied password. If no password is supplied then the currently set credential is used.
NOTE: Keep in mind that if no credential is set, or it's null, or an empty string, this will still return a valid hash of that empty value using the defined encryption hash chain.
Parameters
Parameter | Type | Description |
---|---|---|
$credential | string |
authenticate
Authenticates a user based on the provided identity and credential.
public authenticate({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$identity | string | The identity of the user (e.g., username or email). |
$credential | string | The credential of the user (e.g., password). |
$autologin | bool | whether to enable autologin |
authenticateRequest
Authenticates an HTTP request using Basic Authentication.
public authenticateRequest({Array})
This method checks if the request contains a valid 'Authorization' header with Basic Authentication credentials. It decodes the credentials and verifies them using the authenticate
method.
Parameters
Parameter | Type | Description |
---|---|---|
$request | Request | the HTTP request to authenticate |
authenticated
Checks if the user is authenticated.
public authenticated({Array})
This method verifies if the storage is not empty and contains an 'identity' key. If the storage is empty or does not have the 'identity' key, it clears the storage and returns false. Otherwise, it returns true indicating the user is authenticated.
check
Check that the supplied password is correct for the current identity.
public check({Array})
This is useful for checking an account password before allowing something important to be updated. This does the same steps as authenticate() but doesn't actually do the authentication.
Parameters
Parameter | Type | Description |
---|---|---|
$credential | string |
clear
Clears the authentication storage.
public clear({Array})
This method checks if the storage is empty. If it is not empty, it clears the storage and returns true. If the storage is already empty, it returns false.
unauthorised
Helper method that sets the basic auth header and throws an unauthorised exception.
public unauthorised({Array})
disableCredentialHashing
Toggles on/off the internal credential hashing algorithm.
public disableCredentialHashing({Array})
This is useful is you want to authenticate with an already hashed credential.
WARNING: This should NOT normally be used. And if it IS used, it should only be used to authenticate credentials supplied internally by the application itself, and not provided by a user/client/etc. Disabling password hash essentially turns this all into clear text credentials.
Parameters
Parameter | Type | Description |
---|---|---|
$value | bool |
get
Retrieves a value from the storage based on the provided key.
public get({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key used to retrieve the value from the storage |
set
Sets a value in the storage with the specified key.
public set({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key under which the value will be stored |
$value | mixed | the value to be stored |
has
Checks if a given key exists in the storage.
public has({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to check for existence in the storage |
public ({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string |
offsetExists
public offsetExists({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed |
offsetGet
public offsetGet({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed |
offsetSet
public offsetSet({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed | |
$value | mixed |
offsetUnset
public offsetUnset({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed |
getAuthData
Retrieves authentication data from the storage.
public getAuthData({Array})
getToken
Returns the storage session token.
public getToken({Array})
setStorageAdapter
Sets the storage adapter for authentication.
public setStorageAdapter({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$storage | string | the name of the storage adapter to use |
$options | Map | optional configuration options for the storage adapter |
getIdentifier
Generates a hashed identifier for the given identity string.
protected getIdentifier({Array})
This method takes an identity string and returns its SHA-1 hash. If the identity string is empty or null, the method returns null.
Parameters
Parameter | Type | Description |
---|---|---|
$identity | string | the identity string to be hashed |
setDataFields
Set the extra data fields.
protected setDataFields({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$fields | array | The extra data fields |
authenticationSuccess
Overload function called when a user is successfully authenticated.
protected authenticationSuccess({Array})
This can occur when calling authenticate() or authenticated() where a session has been saved. This default method does nothing but can be overridden.
Parameters
Parameter | Type | Description |
---|---|---|
$identity | string | The identity that was successfully authenticated |
$data | array | The data returned from the authentication query |
authenticationFailure
Overload function called when a user fails authentication.
protected authenticationFailure({Array})
This can occur when calling authenticate() or authenticated() where a session has been saved. This default method does nothing but can be overridden.
Parameters
Parameter | Type | Description |
---|---|---|
$identity | string | the identity that failed authentication |
$data | array | the data returned from the authentication query |
Generated by Hazaar API Doc Generator