TokenGuard
class TokenGuard implements Guard
Traits
These methods are typically the same across all guards.
Properties
| protected null|TProvider | $provider | The user provider implementation. |
from GuardHelpers |
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected int | $hashSeed | The seed for request credential context keys. |
Methods
Determine if the current user is authenticated. If not, throw an exception.
Get this guard's coroutine context key for the given entry.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new authentication guard.
Get the currently authenticated user.
Get the token for the current request.
Validate a user's credentials.
Determine if the guard has a user instance.
Forget the current user.
Get durable authentication Context keys.
Get the Context key for an explicitly assigned user.
Get the Context key for caching the authenticated user, keyed by token.
Flush all static state.
Details
in
GuardHelpers at line 55
Authenticatable
authenticate()
Determine if the current user is authenticated. If not, throw an exception.
in
GuardHelpers at line 63
bool
check()
Determine if the current user is authenticated.
in
GuardHelpers at line 71
bool
guest()
Determine if the current user is a guest.
in
GuardHelpers at line 79
int|string|null
id()
Get the ID for the currently authenticated user.
in
GuardHelpers at line 89
UserProvider|null
getProvider()
Get the user provider used by the guard.
in
GuardHelpers at line 102
void
setProvider(UserProvider $provider)
Set the user provider used by the guard.
The provider is stored on the worker-lifetime guard and affects every subsequent request.
in
GuardHelpers at line 111
protected string
contextKey(string $key)
Get this guard's coroutine context key for the given entry.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 39
__construct(string $name, UserProvider $provider, Container $app, string $inputKey = 'api_token', string $storageKey = 'api_token', bool $hash = false)
Create a new authentication guard.
at line 58
Authenticatable|null
user()
Get the currently authenticated user.
RequestContext keeps resolved users local to the coroutine and clears them when its request changes. Token fingerprints separate credentials, and a sentinel caches "no user found" to avoid redundant provider lookups.
at line 97
string|null
getTokenForRequest()
Get the token for the current request.
at line 127
bool
validate(array $credentials = [])
Validate a user's credentials.
at line 143
bool
hasUser()
Determine if the guard has a user instance.
at line 161
Guard
setUser(Authenticatable $user)
Set the current user.
at line 173
TokenGuard
forgetUser()
Forget the current user.
at line 188
array
getAuthContextKeys()
Get durable authentication Context keys.
Per-request token resolution caches must not cross a request boundary.
at line 196
protected string
getExplicitUserContextKey()
Get the Context key for an explicitly assigned user.
at line 204
protected string
getContextKeyForToken(string|null $token)
Get the Context key for caching the authenticated user, keyed by token.
at line 216
static void
flushState()
Flush all static state.