PHP Class Irazasyed\JwtAuthGuard\JwtAuthGuard

Inheritance: implements Illuminate\Contracts\Auth\Guard, use trait Illuminate\Auth\GuardHelpers
Show file Open project: irazasyed/jwt-auth-guard

Protected Properties

Property Type Description
$jwt Tymon\JWTAuth\JWT The JWT instance.
$lastAttempted Illuminate\Contracts\Auth\Authenticatable The user we last attempted to retrieve.
$request Illuminate\Http\Request The request instance.

Public Methods

Method Description
__call ( string $method, array $parameters ) : mixed Magically call the JWT instance.
__construct ( Tymon\JWTAuth\JWT $jwt, Illuminate\Contracts\Auth\UserProvider $provider, Illuminate\Http\Request $request ) Create a new authentication guard.
attempt ( array $credentials = [], boolean $login = true ) : mixed Attempt to authenticate the user using the given credentials and return the token.
generateTokenById ( mixed $id ) : string | null Generate new token by ID.
getLastAttempted ( ) : Illuminate\Contracts\Auth\Authenticatable Get the last user we attempted to authenticate.
getPayload ( ) : Tymon\JWTAuth\Payload Get the raw Payload instance.
getProvider ( ) : Illuminate\Contracts\Auth\UserProvider Get the user provider used by the guard.
getToken ( ) : false | Token Get the token.
getUser ( ) : Illuminate\Contracts\Auth\Authenticatable | null Return the currently cached user.
invalidate ( boolean $forceForever = false ) : boolean Invalidate current token (add it to the blacklist).
login ( Tymon\JWTAuth\Contracts\JWTSubject $user ) : string Create a token for a user.
logout ( boolean $forceForever = true ) : boolean Logout the user.
once ( array $credentials = [] ) : boolean Log a user into the application without sessions or cookies.
onceUsingId ( mixed $id ) : boolean Log the given user ID into the application without sessions or cookies.
refresh ( ) : string Refresh current expired token.
setProvider ( Illuminate\Contracts\Auth\UserProvider $provider ) Set the user provider used by the guard.
setRequest ( Illuminate\Http\Request $request ) Set the current request instance.
setToken ( Token | string $token ) : JwtGuard Set the token.
user ( ) : Illuminate\Contracts\Auth\Authenticatable | null Get the currently authenticated user.
validate ( array $credentials = [] ) : boolean Validate a user's credentials.

Protected Methods

Method Description
hasValidCredentials ( mixed $user, array $credentials ) : boolean Determine if the user matches the credentials.
requireToken ( ) : Tymon\JWTAuth\JWT Ensure that a token is available in the request.

Method Details

__call() public method

Magically call the JWT instance.
public __call ( string $method, array $parameters ) : mixed
$method string
$parameters array
return mixed

__construct() public method

Create a new authentication guard.
public __construct ( Tymon\JWTAuth\JWT $jwt, Illuminate\Contracts\Auth\UserProvider $provider, Illuminate\Http\Request $request )
$jwt Tymon\JWTAuth\JWT
$provider Illuminate\Contracts\Auth\UserProvider
$request Illuminate\Http\Request

attempt() public method

Attempt to authenticate the user using the given credentials and return the token.
public attempt ( array $credentials = [], boolean $login = true ) : mixed
$credentials array
$login boolean
return mixed

generateTokenById() public method

Generate new token by ID.
public generateTokenById ( mixed $id ) : string | null
$id mixed
return string | null

getLastAttempted() public method

Get the last user we attempted to authenticate.
public getLastAttempted ( ) : Illuminate\Contracts\Auth\Authenticatable
return Illuminate\Contracts\Auth\Authenticatable

getPayload() public method

Get the raw Payload instance.
public getPayload ( ) : Tymon\JWTAuth\Payload
return Tymon\JWTAuth\Payload

getProvider() public method

Get the user provider used by the guard.
public getProvider ( ) : Illuminate\Contracts\Auth\UserProvider
return Illuminate\Contracts\Auth\UserProvider

getToken() public method

Get the token.
public getToken ( ) : false | Token
return false | Token

getUser() public method

Return the currently cached user.
public getUser ( ) : Illuminate\Contracts\Auth\Authenticatable | null
return Illuminate\Contracts\Auth\Authenticatable | null

hasValidCredentials() protected method

Determine if the user matches the credentials.
protected hasValidCredentials ( mixed $user, array $credentials ) : boolean
$user mixed
$credentials array
return boolean

invalidate() public method

Invalidate current token (add it to the blacklist).
public invalidate ( boolean $forceForever = false ) : boolean
$forceForever boolean
return boolean

login() public method

Create a token for a user.
public login ( Tymon\JWTAuth\Contracts\JWTSubject $user ) : string
$user Tymon\JWTAuth\Contracts\JWTSubject
return string

logout() public method

Logout the user.
public logout ( boolean $forceForever = true ) : boolean
$forceForever boolean
return boolean

once() public method

Log a user into the application without sessions or cookies.
public once ( array $credentials = [] ) : boolean
$credentials array
return boolean

onceUsingId() public method

Log the given user ID into the application without sessions or cookies.
public onceUsingId ( mixed $id ) : boolean
$id mixed
return boolean

refresh() public method

Refresh current expired token.
public refresh ( ) : string
return string

requireToken() protected method

Ensure that a token is available in the request.
protected requireToken ( ) : Tymon\JWTAuth\JWT
return Tymon\JWTAuth\JWT

setProvider() public method

Set the user provider used by the guard.
public setProvider ( Illuminate\Contracts\Auth\UserProvider $provider )
$provider Illuminate\Contracts\Auth\UserProvider

setRequest() public method

Set the current request instance.
public setRequest ( Illuminate\Http\Request $request )
$request Illuminate\Http\Request

setToken() public method

Set the token.
public setToken ( Token | string $token ) : JwtGuard
$token Token | string
return JwtGuard

user() public method

Get the currently authenticated user.
public user ( ) : Illuminate\Contracts\Auth\Authenticatable | null
return Illuminate\Contracts\Auth\Authenticatable | null

validate() public method

Validate a user's credentials.
public validate ( array $credentials = [] ) : boolean
$credentials array
return boolean

Property Details

$jwt protected property

The JWT instance.
protected JWT,Tymon\JWTAuth $jwt
return Tymon\JWTAuth\JWT

$lastAttempted protected property

The user we last attempted to retrieve.
protected Authenticatable,Illuminate\Contracts\Auth $lastAttempted
return Illuminate\Contracts\Auth\Authenticatable

$request protected property

The request instance.
protected Request,Illuminate\Http $request
return Illuminate\Http\Request