class JwtAuthGuard implements Guard

Jwt Guard

Traits

GuardHelpers

Properties

protected Authenticatable $lastAttempted

The user we last attempted to retrieve.

protected JWT $jwt

The JWT instance.

protected Request $request

The request instance.

Methods

__construct(JWT $jwt, UserProvider $provider, Request $request)

Create a new authentication guard.

Authenticatable|null
user()

Get the currently authenticated user.

bool
once(array $credentials = [])

Log a user into the application without sessions or cookies.

bool
validate(array $credentials = [])

Validate a user's credentials.

mixed
attempt(array $credentials = [], bool $login = true)

Attempt to authenticate the user using the given credentials and return the token.

string
login(JWTSubject $user)

Create a token for a user.

bool
onceUsingId(mixed $id)

Log the given user ID into the application without sessions or cookies.

void
logout(bool $forceForever = true)

Logout the user.

string|null
generateTokenById(mixed $id)

Generate new token by ID.

string
refresh()

Refresh current expired token.

JWT
invalidate(bool $forceForever = false)

Invalidate current token (add it to the blacklist).

false|Token
getToken()

Get the token.

setToken(Token|string $token)

Set the token.

Payload
getPayload()

Get the raw Payload instance.

bool
hasValidCredentials(mixed $user, array $credentials)

Determine if the user matches the credentials.

JWT
requireToken()

Ensure that a token is available in the request.

Authenticatable
getLastAttempted()

Get the last user we attempted to authenticate.

Authenticatable|null
getUser()

Return the currently cached user.

UserProvider
getProvider()

Get the user provider used by the guard.

$this
setProvider(UserProvider $provider)

Set the user provider used by the guard.

$this
setRequest(Request $request)

Set the current request instance.

mixed
__call(string $method, array $parameters)

Magically call the JWT instance.

Details

at line 48
__construct(JWT $jwt, UserProvider $provider, Request $request)

Create a new authentication guard.

Parameters

JWT $jwt
UserProvider $provider
Request $request

at line 59
Authenticatable|null user()

Get the currently authenticated user.

Return Value

Authenticatable|null

at line 76
bool once(array $credentials = [])

Log a user into the application without sessions or cookies.

Parameters

array $credentials 凭证

Return Value

bool

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

Validate a user's credentials.

Parameters

array $credentials 凭证

Return Value

bool

at line 103
mixed attempt(array $credentials = [], bool $login = true)

Attempt to authenticate the user using the given credentials and return the token.

Parameters

array $credentials 凭证
bool $login 是否尝试登录

Return Value

mixed

at line 118
string login(JWTSubject $user)

Create a token for a user.

Parameters

JWTSubject $user 用户

Return Value

string

at line 130
bool onceUsingId(mixed $id)

Log the given user ID into the application without sessions or cookies.

Parameters

mixed $id ID

Return Value

bool

at line 146
void logout(bool $forceForever = true)

Logout the user.

Parameters

bool $forceForever 是否强制退出

Return Value

void

at line 158
string|null generateTokenById(mixed $id)

Generate new token by ID.

Parameters

mixed $id ID

Return Value

string|null

at line 169
string refresh()

Refresh current expired token.

Return Value

string 刷新

at line 179
JWT invalidate(bool $forceForever = false)

Invalidate current token (add it to the blacklist).

Parameters

bool $forceForever 禁用/加入黑名单

Return Value

JWT

at line 188
false|Token getToken()

Get the token.

Return Value

false|Token

at line 198
JwtAuthGuard setToken(Token|string $token)

Set the token.

Parameters

Token|string $token Token

Return Value

JwtAuthGuard

at line 209
Payload getPayload()

Get the raw Payload instance.

Return Value

Payload

at line 220
protected bool hasValidCredentials(mixed $user, array $credentials)

Determine if the user matches the credentials.

Parameters

mixed $user 用户
array $credentials 凭证

Return Value

bool

at line 230
protected JWT requireToken()

Ensure that a token is available in the request.

Return Value

JWT

Exceptions

BadRequestHttpException

at line 243
Authenticatable getLastAttempted()

Get the last user we attempted to authenticate.

Return Value

Authenticatable

at line 252
Authenticatable|null getUser()

Return the currently cached user.

Return Value

Authenticatable|null

at line 261
UserProvider getProvider()

Get the user provider used by the guard.

Return Value

UserProvider

at line 271
$this setProvider(UserProvider $provider)

Set the user provider used by the guard.

Parameters

UserProvider $provider 服务提供者

Return Value

$this

at line 283
$this setRequest(Request $request)

Set the current request instance.

Parameters

Request $request 设置请求

Return Value

$this

at line 297
mixed __call(string $method, array $parameters)

Magically call the JWT instance.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException