Tsugi

JWT
in package

JSON Web Token implementation

Minimum implementation used by Realtime auth, based on this spec: http://self-issued.info/docs/draft-jones-json-web-token-01.html.

Tags
author

Neuman Vong neuman@twilio.com

Table of Contents

Methods

decode()  : object
encode()  : string
jsonDecode()  : object
jsonEncode()  : string
sign()  : string
urlsafeB64Decode()  : string
urlsafeB64Encode()  : string
handleJsonError()  : void

Methods

decode()

public static decode(string $jwt[, string|null $key = null ][, bool $verify = true ]) : object
Parameters
$jwt : string

The JWT

$key : string|null = null

The secret key

$verify : bool = true

Don't skip verification process

Return values
object —

The JWT's payload as a PHP object

encode()

public static encode(object|array<string|int, mixed> $payload, string $key[, string $algo = 'HS256' ]) : string
Parameters
$payload : object|array<string|int, mixed>

PHP object or array

$key : string

The secret key

$algo : string = 'HS256'

The signing algorithm

Return values
string —

A self

jsonDecode()

public static jsonDecode(string $input) : object
Parameters
$input : string

JSON string

Return values
object —

Object representation of JSON string

jsonEncode()

public static jsonEncode(object|array<string|int, mixed> $input) : string
Parameters
$input : object|array<string|int, mixed>

A PHP object or array

Return values
string —

JSON representation of the PHP object or array

sign()

public static sign(string $msg, string $key[, string $method = 'HS256' ]) : string
Parameters
$msg : string

The message to sign

$key : string

The secret key

$method : string = 'HS256'

The signing algorithm

Return values
string —

An encrypted message

urlsafeB64Decode()

public static urlsafeB64Decode(string $input) : string
Parameters
$input : string

A base64 encoded string

Return values
string —

A decoded string

urlsafeB64Encode()

public static urlsafeB64Encode(string $input) : string
Parameters
$input : string

Anything really

Return values
string —

The base64 encode of what you passed in

handleJsonError()

private static handleJsonError(int $errno) : void
Parameters
$errno : int

An error number from json_last_error()


        
On this page

Search results