PHP Class GenTux\Jwt\JwtToken

Inheritance: implements JsonSerializabl\JsonSerializable
Show file Open project: generationtux/jwt-artisan Class Usage Examples

Public Methods

Method Description
__construct ( GenTux\Jwt\Drivers\JwtDriverInterface $jwt, string | null $secret = null, string | null $algorithm = null )
__toString ( ) : string Convert into string
algorithm ( ) : string Get the algorithm to use
createToken ( GenTux\Jwt\JwtPayloadInterface | array $payload, string | null $secret = null, string | null $algo = null ) : JwtToken Create a new token with the provided payload
jsonSerialize ( ) : mixed Specify data which should be serialized to JSON
payload ( string | null $path = null, string | null $secret = null, string | null $algo = null ) : array Get the payload from the current token
secret ( ) : string Get the secret to use for token operations
setAlgorithm ( string $algo ) : self Set the algorithm to use
setSecret ( string $secret ) : self Set the secret to use for token operations
setToken ( string $token ) : self Set the current JWT token
token ( ) : string Get the current JWT token
validate ( string | null $secret = null, string | null $algo = null ) : boolean Validate a token
validateOrFail ( string | null $secret = null, string | null $algo = null ) : boolean Validate the token or throw an exception

Private Methods

Method Description
queryPayload ( array $payload, string | null $path = null ) : mixed Query the payload using dot syntax to find specific data

Method Details

__construct() public method

public __construct ( GenTux\Jwt\Drivers\JwtDriverInterface $jwt, string | null $secret = null, string | null $algorithm = null )
$jwt GenTux\Jwt\Drivers\JwtDriverInterface
$secret string | null
$algorithm string | null

__toString() public method

Convert into string
public __toString ( ) : string
return string

algorithm() public method

This can be customized by setting the env variable JWT_ALGO
public algorithm ( ) : string
return string

createToken() public method

The default algorithm used is HS256. To set a custom one, set the env variable JWT_ALGO.
public createToken ( GenTux\Jwt\JwtPayloadInterface | array $payload, string | null $secret = null, string | null $algo = null ) : JwtToken
$payload GenTux\Jwt\JwtPayloadInterface | array
$secret string | null
$algo string | null
return JwtToken

jsonSerialize() public method

Specify data which should be serialized to JSON
public jsonSerialize ( ) : mixed
return mixed data which can be serialized by json_encode, which is a value of any type other than a resource.

payload() public method

Get the payload from the current token
public payload ( string | null $path = null, string | null $secret = null, string | null $algo = null ) : array
$path string | null dot syntax to query for specific data
$secret string | null
$algo string | null
return array

secret() public method

Get the secret to use for token operations
public secret ( ) : string
return string

setAlgorithm() public method

Set the algorithm to use
public setAlgorithm ( string $algo ) : self
$algo string
return self

setSecret() public method

Set the secret to use for token operations
public setSecret ( string $secret ) : self
$secret string
return self

setToken() public method

Set the current JWT token
public setToken ( string $token ) : self
$token string
return self

token() public method

Get the current JWT token
public token ( ) : string
return string

validate() public method

Validate a token
public validate ( string | null $secret = null, string | null $algo = null ) : boolean
$secret string | null
$algo string | null
return boolean

validateOrFail() public method

Validate the token or throw an exception
public validateOrFail ( string | null $secret = null, string | null $algo = null ) : boolean
$secret string | null
$algo string | null
return boolean