Auth ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Auth » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 5.0.0
User authentication service.
An instance of the service is globally accessible in Craft via Craft::$app->getAuth().
Public Properties ​
| Property | Description |
|---|---|
| activeMethods | craft\auth\methods\AuthMethodInterface[] |
| allMethods | craft\auth\methods\AuthMethodInterface[] |
| authErrorMessage | string |
| availableMethods | craft\auth\methods\AuthMethodInterface[] |
| behaviors | yii\base\Behavior – List of behaviors attached to this component. |
| inputHtml | string |
| passkeyCreationOptionsParam | string – The session variable name used to store passkey credential creation options. |
| passkeyRequestOptions | \Webauthn\PublicKeyCredentialRequestOptions |
| sessionDurationParam | string – The session variable name used to store the number of seconds that the user can remain logged-in. |
| user | craft\elements\User, null |
| userIdParam | string – The session variable name used to store the ID of the user being authenticated. |
activeMethods ​
- Type
- craft\auth\methods\AuthMethodInterface[]
- Default value
null- Access
- Read-only
allMethods ​
- Type
- craft\auth\methods\AuthMethodInterface[]
- Default value
null- Access
- Read-only
authErrorMessage ​
- Type
- string
- Default value
null- Access
- Read-only
- Since
- 5.7.11
availableMethods ​
- Type
- craft\auth\methods\AuthMethodInterface[]
- Default value
null- Access
- Read-only
inputHtml ​
- Type
- string
- Default value
null- Access
- Read-only
passkeyCreationOptionsParam ​
- Type
- string
- Default value
null
The session variable name used to store passkey credential creation options.
passkeyRequestOptions ​
- Type
\Webauthn\PublicKeyCredentialRequestOptions- Default value
null- Access
- Read-only
sessionDurationParam ​
- Type
- string
- Default value
null
The session variable name used to store the number of seconds that the user can remain logged-in.
user ​
- Type
- craft\elements\User, null
- Default value
null
userIdParam ​
- Type
- string
- Default value
null
The session variable name used to store the ID of the user being authenticated.
Public Methods ​
| Method | Description |
|---|---|
| __call() | Calls the named method which is not a class method. |
| __clone() | This method is called after the object is created by cloning an existing one. |
| __construct() | Constructor. |
| __get() | Returns the value of a component property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __set() | Sets the value of a component property. |
| __unset() | Sets a component property to be null. |
| attachBehavior() | Attaches a behavior to this component. |
| attachBehaviors() | Attaches a list of behaviors to the component. |
| behaviors() | Returns a list of behaviors that this component should behave as. |
| canGetProperty() | Returns a value indicating whether a property can be read. |
| canSetProperty() | Returns a value indicating whether a property can be set. |
| className() | Returns the fully qualified name of this class. |
| deletePasskey() | Deletes a passkey. |
| detachBehavior() | Detaches a behavior from the component. |
| detachBehaviors() | Detaches all behaviors from the component. |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
| getActiveMethods() | Returns the authentication methods that are active for the given user. |
| getAllMethods() | Returns all available user authentication methods. |
| getAuthErrorMessage() | Returns an authentication error message based on the authentication error value. |
| getAvailableMethods() | Returns the authentication methods that are available for the given user. |
| getBehavior() | Returns the named behavior object. |
| getBehaviors() | Returns all behaviors attached to this component. |
| getInputHtml() | Get html of the form for the 2FA step |
| getMethod() | Returns an authentication method by its class name. |
| getPasskeyCreationOptions() | Generates new passkey credential creation options for the given user. |
| getPasskeyRequestOptions() | Returns the public key credential request options. |
| getPasskeys() | Returns info about the given user’s saved passkeys. |
| getUser() | Get user and duration data from session |
| hasActiveMethod() | Returns whether any authentication methods are active for the given user. |
| hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
| hasMethod() | Returns a value indicating whether a method is defined. |
| hasPasskeys() | Returns whether the given user has passkeys. |
| hasProperty() | Returns a value indicating whether a property is defined for this component. |
| init() | |
| is2faRequired() | Returns whether 2FA is required for a user. |
| off() | Detaches an existing event handler from this component. |
| on() | Attaches an event handler to an event. |
| setUser() | Stores the user being logged-in, along with the expected session duration. |
| trigger() | Triggers an event. |
| verify() | Authenticates the user. |
| verifyPasskey() | Verifies a passkey authentication response and stores the passkey. |
| verifyPasskeyCreationResponse() | Verifies a passkey creation response and stores the passkey. |
deletePasskey() ​
Deletes a passkey.
Arguments ​
$user(craft\elements\User)$uid(string)
getActiveMethods() ​
Returns the authentication methods that are active for the given user.
Arguments ​
$user(craft\elements\User, null)
Returns ​
craft\auth\methods\AuthMethodInterface[]
getAllMethods() ​
Returns all available user authentication methods.
Arguments ​
$user(craft\elements\User, null)
Returns ​
craft\auth\methods\AuthMethodInterface[]
getAuthErrorMessage() ​
- Since
- 5.7.11
Returns an authentication error message based on the authentication error value.
If a default message was passed and the authentication error value is for invalid credentials, that default message will be used.
Arguments ​
Returns ​
getAvailableMethods() ​
Returns the authentication methods that are available for the given user.
Arguments ​
$user(craft\elements\User, null)
Returns ​
craft\auth\methods\AuthMethodInterface[]
getInputHtml() ​
Get html of the form for the 2FA step
Returns ​
getMethod() ​
Returns an authentication method by its class name.
Arguments ​
$class(class-string<\craft\services\T>)$user(craft\elements\User, null)
Returns ​
\craft\services\T
Throws ​
getPasskeyCreationOptions() ​
Generates new passkey credential creation options for the given user.
Arguments ​
$user(craft\elements\User)
Returns ​
\Webauthn\PublicKeyCredentialOptions
getPasskeyRequestOptions() ​
Returns the public key credential request options.
Returns ​
\Webauthn\PublicKeyCredentialRequestOptions
getPasskeys() ​
Returns info about the given user’s saved passkeys.
Arguments ​
$user(craft\elements\User)
Returns ​
array{credentialName: string, dateLasteUsed: \DateTime, uid: string}[]
getUser() ​
Get user and duration data from session
Arguments ​
Returns ​
hasActiveMethod() ​
Returns whether any authentication methods are active for the given user.
Arguments ​
$user(craft\elements\User, null)
Returns ​
hasPasskeys() ​
Returns whether the given user has passkeys.
Arguments ​
$user(craft\elements\User)
Returns ​
init() ​
is2faRequired() ​
Returns whether 2FA is required for a user.
Arguments ​
$user(craft\elements\User)
Returns ​
setUser() ​
Stores the user being logged-in, along with the expected session duration.
Arguments ​
$user(craft\elements\User, null)$sessionDuration(integer, null)
verify() ​
Authenticates the user.
Any arguments
Arguments ​
$methodClass(class-string<\craft\auth\methods\AuthMethodInterface>)$args(mixed) – ,...
Returns ​
verifyPasskey() ​
Verifies a passkey authentication response and stores the passkey.
Arguments ​
$user(craft\elements\User)$requestOptions(\Webauthn\PublicKeyCredentialRequestOptions, array, string) – The public key credential request options$response(string) – The authentication response data
Returns ​
verifyPasskeyCreationResponse() ​
Verifies a passkey creation response and stores the passkey.
Arguments ​
Returns ​
Events ​
EVENT_REGISTER_METHODS ​
The event that is triggered when registering user authentication methods.
See also getAllMethods()