Documentation

Jwt
in package

Common Jws/Jwt methods

For spec and definitions,

Tags
see:

https://datatracker.ietf.org/doc/html/rfc7519#section-4.1

Table of Contents

Methods

buildWithJwk()  : JWS
Create a JWS with a specified key and a given algorithm
createJwsWithKeyFile()  : JWS
Create a JWS with a specified key (pem) via file path
createJwsWithKeyString()  : JWS
Create a JWS with a specified key
getPayload()  : array<string|int, mixed>
Get the payload from either a raw string or a JWS object
serialize()  : string
Serialize a JWS to a string
unserialize()  : JWS
Unserialize a JWS from a string
validatePayload()  : bool
Common payload validation on expiry and issuance dates
verifyWithKeyFile()  : bool
Verify a JWS with a specified key file, within a range of acceptable algorithms
verifyWithKeyString()  : bool
Verify a JWS with a specified key, within a range of acceptable algorithms

Methods

buildWithJwk()

Create a JWS with a specified key and a given algorithm

public static buildWithJwk(array<string|int, mixed> $payload, JWK $jwk, Algorithm $algorithm) : JWS
Parameters
$payload : array<string|int, mixed>
$jwk : JWK
$algorithm : Algorithm
Tags
throws
LogicException
InvalidArgumentException
RuntimeException
Return values
JWS

createJwsWithKeyFile()

Create a JWS with a specified key (pem) via file path

public static createJwsWithKeyFile(array<string|int, mixed> $payload, string $signing_key_path, Algorithm $algorithm[, array<string|int, mixed> $additional_values = [] ]) : JWS
Parameters
$payload : array<string|int, mixed>
$signing_key_path : string

A key location to sign with

$algorithm : Algorithm

A specific algorithm eg RS256 or HS256

$additional_values : array<string|int, mixed> = []
Return values
JWS

createJwsWithKeyString()

Create a JWS with a specified key

public static createJwsWithKeyString(array<string|int, mixed> $payload, string $signing_key, Algorithm $algorithm[, array<string|int, mixed> $additional_values = [] ]) : JWS
Parameters
$payload : array<string|int, mixed>
$signing_key : string

A key string to sign with

$algorithm : Algorithm

A specific algorithm eg RS256 or HS256

$additional_values : array<string|int, mixed> = []
Return values
JWS

getPayload()

Get the payload from either a raw string or a JWS object

public static getPayload(JWS|string $jws) : array<string|int, mixed>
Parameters
$jws : JWS|string
Return values
array<string|int, mixed>

serialize()

Serialize a JWS to a string

public static serialize(JWS $jws) : string
Parameters
$jws : JWS
Return values
string

unserialize()

Unserialize a JWS from a string

public static unserialize(string $jws) : JWS
Parameters
$jws : string
Return values
JWS

validatePayload()

Common payload validation on expiry and issuance dates

public static validatePayload(array<string|int, mixed> $payload, bool $throw_on_error) : bool
Parameters
$payload : array<string|int, mixed>
$throw_on_error : bool
Tags
throws
JwtException
Return values
bool

verifyWithKeyFile()

Verify a JWS with a specified key file, within a range of acceptable algorithms

public static verifyWithKeyFile(JWS $jws, string $signing_key_path, array<string|int, mixed> $algorithms) : bool
Parameters
$jws : JWS
$signing_key_path : string

A key location to validate against

$algorithms : array<string|int, mixed>

e.g. $algorithms = [new HS256()];

Return values
bool

verifyWithKeyString()

Verify a JWS with a specified key, within a range of acceptable algorithms

public static verifyWithKeyString(JWS $jws, string $signing_key, array<string|int, mixed> $algorithms) : bool
Parameters
$jws : JWS
$signing_key : string

A key string to validate against

$algorithms : array<string|int, mixed>

e.g. $algorithms = [new HS256()];

Return values
bool
On this page

Search results