Skip to content

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->auth.

View source

Public Properties ​

PropertyDescription
activeMethodscraft\auth\methods\AuthMethodInterface[]
allMethodscraft\auth\methods\AuthMethodInterface[]
availableMethodscraft\auth\methods\AuthMethodInterface[]
behaviorsyii\base\Behavior – List of behaviors attached to this component.
inputHtmlstring
passkeyCreationOptionsParamstring – The session variable name used to store passkey credential creation options.
passkeyRequestOptions\Webauthn\PublicKeyCredentialRequestOptions
sessionDurationParamstring – The session variable name used to store the number of seconds that the user can remain logged-in.
usercraft\elements\User, null
userIdParamstring – 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

View source

allMethods ​

Type
craft\auth\methods\AuthMethodInterface[]
Default value
null
Access
Read-only

View source

availableMethods ​

Type
craft\auth\methods\AuthMethodInterface[]
Default value
null
Access
Read-only

View source

inputHtml ​

Type
string
Default value
null
Access
Read-only

View source

passkeyCreationOptionsParam ​

Type
string
Default value
null

The session variable name used to store passkey credential creation options.

View source

passkeyRequestOptions ​

Type
\Webauthn\PublicKeyCredentialRequestOptions
Default value
null
Access
Read-only

View source

sessionDurationParam ​

Type
string
Default value
null

The session variable name used to store the number of seconds that the user can remain logged-in.

View source

user ​

Type
craft\elements\User, null
Default value
null

View source

userIdParam ​

Type
string
Default value
null

The session variable name used to store the ID of the user being authenticated.

View source

Public Methods ​

MethodDescription
__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.
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.

View source

Arguments ​

getActiveMethods() ​

Returns the authentication methods that are active for the given user.

View source

Arguments ​

Returns ​

craft\auth\methods\AuthMethodInterface[]

getAllMethods() ​

Returns all available user authentication methods.

View source

Arguments ​

Returns ​

craft\auth\methods\AuthMethodInterface[]

getAvailableMethods() ​

Returns the authentication methods that are available for the given user.

View source

Arguments ​

Returns ​

craft\auth\methods\AuthMethodInterface[]

getInputHtml() ​

Get html of the form for the 2FA step

View source

Returns ​

string

getMethod() ​

Returns an authentication method by its class name.

View source

Arguments ​

Returns ​

\craft\services\T

Throws ​

getPasskeyCreationOptions() ​

Generates new passkey credential creation options for the given user.

View source

Arguments ​

Returns ​

\Webauthn\PublicKeyCredentialOptions

getPasskeyRequestOptions() ​

Returns the public key credential request options.

View source

Returns ​

\Webauthn\PublicKeyCredentialRequestOptions

getPasskeys() ​

Returns info about the given user’s saved passkeys.

View source

Arguments ​

Returns ​

array{credentialName: string, dateLasteUsed: \DateTime, uid: string}[]

getUser() ​

Get user and duration data from session

View source

Arguments ​

Returns ​

craft\elements\User, null

hasActiveMethod() ​

Returns whether any authentication methods are active for the given user.

View source

Arguments ​

Returns ​

boolean

hasPasskeys() ​

Returns whether the given user has passkeys.

View source

Arguments ​

Returns ​

boolean

init() ​

View source

is2faRequired() ​

Returns whether 2FA is required for a user.

View source

Arguments ​

Returns ​

boolean

setUser() ​

Stores the user being logged-in, along with the expected session duration.

View source

Arguments ​

verify() ​

Authenticates the user.

Any arguments

View source

Arguments ​

  • $methodClass (class-string<\craft\auth\methods\AuthMethodInterface>)
  • $args (mixed) – ,...

Returns ​

boolean

verifyPasskey() ​

Verifies a passkey authentication response and stores the passkey.

View source

Arguments ​

  • $user (craft\elements\User)
  • $requestOptions (\Webauthn\PublicKeyCredentialRequestOptions, array, string) – The public key credential request options
  • $response (string) – The authentication response data

Returns ​

boolean

verifyPasskeyCreationResponse() ​

Verifies a passkey creation response and stores the passkey.

View source

Arguments ​

Returns ​

boolean

Events ​

EVENT_REGISTER_METHODS ​

Type
craft\events\RegisterComponentTypesEvent

The event that is triggered when registering user authentication methods.

See also getAllMethods()