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

authenticate()

Determine if the current user is authenticated. If not, throw an exception.

bool
check()

Determine if the current user is authenticated.

bool
guest()

Determine if the current user is a guest.

int|string|null
id()

Get the ID for the currently authenticated user.

getProvider()

Get the user provider used by the guard.

void
setProvider(UserProvider $provider)

Set the user provider used by the guard.

string
contextKey(string $key)

Get this guard's coroutine context key for the given entry.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(string $name, ServerFactory $servers, PassportUserProvider $provider, ClientRepository $clients, Encrypter $encrypter, Container $app)

Create a new token guard instance.

user()

Get the user for the incoming request.

bool
validate(array $credentials = [])

Validate a user's credentials.

Client|null
client()

Get the client for the incoming request.

token()

Get the validated bearer token for the current request.

bool
hasAccessToken(Request $request)

Determine whether the request supplies a Bearer or DPoP credential.

authenticateViaBearerToken(Request $request, bool $cache = true)

Authenticate the incoming request via the Bearer token.

ServerRequestInterface|null
getPsrRequestViaBearerToken(Request $request, bool $cache = true)

Authenticate and get the incoming PSR-7 request via the Bearer token.

authenticateViaCookie(Request $request)

Authenticate the incoming request via the token cookie.

array|null
getTokenViaCookie(Request $request)

Get the token cookie via the incoming request.

array
decodeJwtTokenCookie(Request $request)

Decode and decrypt the JWT token cookie.

bool
validCsrf(array $token, Request $request)

Determine if the CSRF / header are valid and match.

string|null
getTokenFromRequest(Request $request)

Get the CSRF token from the request.

static bool
serialized()

Determine if the cookie contents should be serialized.

setClient(Client $client)

Set the client for the current request.

bool
hasUser()

Determine if the guard has a user instance.

setUser(Authenticatable $user)

Set the current user.

forgetUser()

Forget the current user.

array
getAuthContextKeys()

Get durable authentication context keys.

string
getExplicitUserContextKey()

Get the context key for an explicitly assigned user.

string
getExplicitClientContextKey()

Get the context key for an explicitly assigned client.

string
getContextKey(Request $request, string $type)

Get the context key for credentials resolved in the current request.

static void
flushState()

Flush all static state.

Details

in GuardHelpers at line 55
Authenticatable authenticate()

Determine if the current user is authenticated. If not, throw an exception.

Return Value

Authenticatable

Exceptions

AuthenticationException

in GuardHelpers at line 63
bool check()

Determine if the current user is authenticated.

Return Value

bool

in GuardHelpers at line 71
bool guest()

Determine if the current user is a guest.

Return Value

bool

in GuardHelpers at line 79
int|string|null id()

Get the ID for the currently authenticated user.

Return Value

int|string|null

in GuardHelpers at line 89
UserProvider|null getProvider()

Get the user provider used by the guard.

Return Value

UserProvider|null

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.

Parameters

UserProvider $provider

Return Value

void

in GuardHelpers at line 111
protected string contextKey(string $key)

Get this guard's coroutine context key for the given entry.

Parameters

string $key

Return Value

string

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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 83
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 108
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 59
__construct(string $name, ServerFactory $servers, PassportUserProvider $provider, ClientRepository $clients, Encrypter $encrypter, Container $app)

Create a new token guard instance.

Parameters

string $name
ServerFactory $servers
PassportUserProvider $provider
ClientRepository $clients
Encrypter $encrypter
Container $app

at line 76
Authenticatable|null user()

Get the user for the incoming request.

Return Value

Authenticatable|null

at line 115
bool validate(array $credentials = [])

Validate a user's credentials.

Parameters

array $credentials

Return Value

bool

at line 129
Client|null client()

Get the client for the incoming request.

Return Value

Client|null

at line 162
AccessToken|null token()

Get the validated bearer token for the current request.

Return Value

AccessToken|null

at line 180
protected bool hasAccessToken(Request $request)

Determine whether the request supplies a Bearer or DPoP credential.

Parameters

Request $request

Return Value

bool

at line 190
protected Authenticatable|null authenticateViaBearerToken(Request $request, bool $cache = true)

Authenticate the incoming request via the Bearer token.

Parameters

Request $request
bool $cache

Return Value

Authenticatable|null

at line 231
protected ServerRequestInterface|null getPsrRequestViaBearerToken(Request $request, bool $cache = true)

Authenticate and get the incoming PSR-7 request via the Bearer token.

Parameters

Request $request
bool $cache

Return Value

ServerRequestInterface|null

at line 246
protected Authenticatable|null authenticateViaCookie(Request $request)

Authenticate the incoming request via the token cookie.

Parameters

Request $request

Return Value

Authenticatable|null

at line 273
protected array|null getTokenViaCookie(Request $request)

Get the token cookie via the incoming request.

Parameters

Request $request

Return Value

array|null

at line 308
protected array decodeJwtTokenCookie(Request $request)

Decode and decrypt the JWT token cookie.

Parameters

Request $request

Return Value

array

at line 325
protected bool validCsrf(array $token, Request $request)

Determine if the CSRF / header are valid and match.

Parameters

array $token
Request $request

Return Value

bool

at line 337
protected string|null getTokenFromRequest(Request $request)

Get the CSRF token from the request.

Parameters

Request $request

Return Value

string|null

at line 357
static bool serialized()

Determine if the cookie contents should be serialized.

Return Value

bool

at line 365
TokenGuard setClient(Client $client)

Set the client for the current request.

Parameters

Client $client

Return Value

TokenGuard

at line 375
bool hasUser()

Determine if the guard has a user instance.

Return Value

bool

at line 395
Guard setUser(Authenticatable $user)

Set the current user.

Parameters

Authenticatable $user

Return Value

Guard

at line 405
TokenGuard forgetUser()

Forget the current user.

Return Value

TokenGuard

at line 421
array getAuthContextKeys()

Get durable authentication context keys.

Return Value

array

at line 429
protected string getExplicitUserContextKey()

Get the context key for an explicitly assigned user.

Return Value

string

at line 437
protected string getExplicitClientContextKey()

Get the context key for an explicitly assigned client.

Return Value

string

at line 445
protected string getContextKey(Request $request, string $type)

Get the context key for credentials resolved in the current request.

Parameters

Request $request
string $type

Return Value

string

at line 463
static void flushState()

Flush all static state.

Return Value

void