UserFrosting API

Authenticator

Handles authentication tasks.

Tags
author

Alex Weissman (https://alexanderweissman.com) Partially inspired by Laravel's Authentication component: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Auth/SessionGuard.php

Table of Contents

$classMapper ClassMapper
$session Session
$config Repository
$cache Repository
$db Manager
$loggedOut bool
$rememberMeStorage PDOStorage
$rememberMe Authenticator
$user UserInterface
$viaRemember Indicates if the user was authenticated via a rememberMe cookie. bool
__construct() Create a new Authenticator object. mixed
attempt() Attempts to authenticate a user based on a supplied identity and password. UserInterface
check() Determine if the current user is authenticated. bool
guest() Determine if the current user is a guest (unauthenticated). bool
login() Process an account login request. mixed
logout() Processes an account logout request. mixed
user() Try to get the currently authenticated user, returning a guest user if none was found. UserInterface|null
viaRemember() Determine whether the current user was authenticated using a remember me cookie. bool
loginRememberedUser() Attempt to log in the client from their rememberMe token (in their cookie). UserInterface|bool
loginSessionUser() Attempt to log in the client from the session. UserInterface|null
validateRememberMeCookie() Determine if the cookie contains a valid rememberMe token. bool
validateUserAccount() Tries to load the specified user by id from the database. UserInterface|null
flushSessionCache() Flush the cache associated with a session id. bool

Properties

$viaRemember

Indicates if the user was authenticated via a rememberMe cookie.

protected bool $viaRemember = false

Methods

__construct()

Create a new Authenticator object.

public __construct( $classMapper : ClassMapper , $session : Session , $config : Repository , $cache : Repository , $db : Manager ) : mixed
Parameters
$classMapper : ClassMapper

Maps generic class identifiers to specific class names.

$session : Session

The session wrapper object that will store the user's id.

$config : Repository

Config object that contains authentication settings.

$cache : Repository

Cache service instance

$db : Manager

Database service instance

Return values
mixed

attempt()

Attempts to authenticate a user based on a supplied identity and password.

public attempt( $identityColumn : string , $identityValue : string , $password : string [, $rememberMe : bool = false ] ) : UserInterface

If successful, the user's id is stored in session.

Parameters
$identityColumn : string
$identityValue : string
$password : string
$rememberMe : bool = false
Tags
throws
InvalidCredentialsException
throws
AccountDisabledException
throws
AccountNotVerifiedException
Return values
UserInterface

check()

Determine if the current user is authenticated.

public check( ) : bool
Return values
bool

guest()

Determine if the current user is a guest (unauthenticated).

public guest( ) : bool
Return values
bool

login()

Process an account login request.

public login( $user : UserInterface [, $rememberMe : bool = false ] ) : mixed

This method logs in the specified user, allowing the client to assume the user's identity for the duration of the session.

Parameters
$user : UserInterface

The user to log in.

$rememberMe : bool = false

Set to true to make this a "persistent session", i.e. one that will re-login even after the session expires.

Tags
todo

Figure out a way to update the currentUser service to reflect the logged-in user immediately in the service provider. As it stands, the currentUser service will still reflect a "guest user" for the remainder of the request.

Return values
mixed

logout()

Processes an account logout request.

public logout( [ $complete : bool = false ] ) : mixed

Logs the currently authenticated user out, destroying the PHP session and clearing the persistent session. This can optionally remove persistent sessions across all browsers/devices, since there can be a "RememberMe" cookie and corresponding database entries in multiple browsers/devices. See http://jaspan.com/improved_persistent_login_cookie_best_practice.

Parameters
$complete : bool = false

If set to true, will ensure that the user is logged out from all browsers on all devices.

Return values
mixed

viaRemember()

Determine whether the current user was authenticated using a remember me cookie.

public viaRemember( ) : bool

This function is useful when users are performing sensitive operations, and you may want to force them to re-authenticate.

Return values
bool

loginRememberedUser()

Attempt to log in the client from their rememberMe token (in their cookie).

protected loginRememberedUser( ) : UserInterface|bool
Tags
throws
AuthCompromisedException

The client attempted to log in with an invalid rememberMe token.

Return values
UserInterface|bool

If successful, the User object of the remembered user. Otherwise, return false.

loginSessionUser()

Attempt to log in the client from the session.

protected loginSessionUser( ) : UserInterface|null
Tags
throws
AuthExpiredException

The client attempted to use an expired rememberMe token.

Return values
UserInterface|null

If successful, the User object of the user in session. Otherwise, return null.

validateRememberMeCookie()

Determine if the cookie contains a valid rememberMe token.

protected validateRememberMeCookie( ) : bool
Return values
bool

flushSessionCache()

Flush the cache associated with a session id.

public flushSessionCache( $id : string ) : bool
Parameters
$id : string

The session id

Return values
bool

Search results