TokenGuard
class TokenGuard implements Guard
Traits
These methods are typically the same across all guards.
Properties
| protected PassportUserProvider | $provider | The user provider implementation. |
|
| 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 token guard instance.
Get the user for the incoming request.
Validate a user's credentials.
Get the validated bearer token for the current request.
Determine whether the request supplies a Bearer or DPoP credential.
Authenticate the incoming request via the Bearer token.
Authenticate and get the incoming PSR-7 request via the Bearer token.
Determine if the cookie contents should be serialized.
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 an explicitly assigned client.
Get the context key for credentials resolved in the current request.
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 59
__construct(string $name, ServerFactory $servers, PassportUserProvider $provider, ClientRepository $clients, Encrypter $encrypter, Container $app)
Create a new token guard instance.
at line 76
Authenticatable|null
user()
Get the user for the incoming request.
at line 115
bool
validate(array $credentials = [])
Validate a user's credentials.
at line 129
Client|null
client()
Get the client for the incoming request.
at line 162
AccessToken|null
token()
Get the validated bearer token for the current request.
at line 180
protected bool
hasAccessToken(Request $request)
Determine whether the request supplies a Bearer or DPoP credential.
at line 190
protected Authenticatable|null
authenticateViaBearerToken(Request $request, bool $cache = true)
Authenticate the incoming request via the Bearer token.
at line 231
protected ServerRequestInterface|null
getPsrRequestViaBearerToken(Request $request, bool $cache = true)
Authenticate and get the incoming PSR-7 request via the Bearer token.
at line 246
protected Authenticatable|null
authenticateViaCookie(Request $request)
Authenticate the incoming request via the token cookie.
at line 273
protected array|null
getTokenViaCookie(Request $request)
Get the token cookie via the incoming request.
at line 308
protected array
decodeJwtTokenCookie(Request $request)
Decode and decrypt the JWT token cookie.
at line 325
protected bool
validCsrf(array $token, Request $request)
Determine if the CSRF / header are valid and match.
at line 337
protected string|null
getTokenFromRequest(Request $request)
Get the CSRF token from the request.
at line 357
static bool
serialized()
Determine if the cookie contents should be serialized.
at line 365
TokenGuard
setClient(Client $client)
Set the client for the current request.
at line 375
bool
hasUser()
Determine if the guard has a user instance.
at line 395
Guard
setUser(Authenticatable $user)
Set the current user.
at line 405
TokenGuard
forgetUser()
Forget the current user.
at line 421
array
getAuthContextKeys()
Get durable authentication context keys.
at line 429
protected string
getExplicitUserContextKey()
Get the context key for an explicitly assigned user.
at line 437
protected string
getExplicitClientContextKey()
Get the context key for an explicitly assigned client.
at line 445
protected string
getContextKey(Request $request, string $type)
Get the context key for credentials resolved in the current request.
at line 463
static void
flushState()
Flush all static state.