DecodedJWT๏ƒ

Inherits: RefCounted < Object

An object-oriented wrapper for parsed JSON Web Tokens.

Description๏ƒ

Returned by JWT.parse(jwt_str), this wrapper caches the decoded header and payload, and provides explicit type checking methods to extract claims.

var t = JWT.parse(jwt_string)
if not t.is_expired():
    var roles = t.get_claim_as_array('roles')

Methods๏ƒ

String

get_algorithm() const

Variant

get_audience() const

Variant

get_claim(key: String) const

Array

get_claim_as_array(key: String) const

bool

get_claim_as_bool(key: String) const

Dictionary

get_claim_as_dictionary(key: String) const

int

get_claim_as_int(key: String) const

String

get_claim_as_string(key: String) const

float

get_expiration_time() const

Dictionary

get_header() const

Variant

get_header_claim(key: String) const

String

get_header_claim_as_string(key: String) const

float

get_issued_at() const

String

get_issuer() const

String

get_jwt_id() const

String

get_kid() const

float

get_not_before() const

Dictionary

get_payload() const

String

get_signature() const

String

get_subject() const

bool

has_claim(key: String) const

bool

has_header_claim(key: String) const

bool

is_expired() const

void

parse(jwt: String)


Method Descriptions๏ƒ

String get_algorithm() const ๐Ÿ”—

Returns the algorithm (alg) specified in the token's header.


Variant get_audience() const ๐Ÿ”—

Extracts the audience (aud) claim. May return a String or an Array depending on the token.


Variant get_claim(key: String) const ๐Ÿ”—

Extracts a claim from the payload as an untyped Variant.


Array get_claim_as_array(key: String) const ๐Ÿ”—

Extracts a claim from the payload and casts it to an Array. Returns an empty Array if the claim does not exist or is not an array.


bool get_claim_as_bool(key: String) const ๐Ÿ”—

Extracts a claim from the payload and casts it to a boolean. Returns false if the claim does not exist.


Dictionary get_claim_as_dictionary(key: String) const ๐Ÿ”—

Extracts a claim from the payload and casts it to a Dictionary.


int get_claim_as_int(key: String) const ๐Ÿ”—

Extracts a claim from the payload and casts it to an integer.


String get_claim_as_string(key: String) const ๐Ÿ”—

Extracts a claim from the payload and casts it to a String.


float get_expiration_time() const ๐Ÿ”—

Returns the expiration time (exp) claim as a float representing UNIX time in seconds.


Dictionary get_header() const ๐Ÿ”—

Returns the entire decoded JWT header as a dictionary.


Variant get_header_claim(key: String) const ๐Ÿ”—

Extracts a specific claim from the JWT header.


String get_header_claim_as_string(key: String) const ๐Ÿ”—

Extracts a specific claim from the JWT header and casts it to a String.


float get_issued_at() const ๐Ÿ”—

Returns the issued at (iat) claim as a float representing UNIX time in seconds.


String get_issuer() const ๐Ÿ”—

Returns the issuer (iss) claim as a String.


String get_jwt_id() const ๐Ÿ”—

Returns the JWT ID (jti) claim as a String.


String get_kid() const ๐Ÿ”—

Returns the Key ID (kid) from the header.


float get_not_before() const ๐Ÿ”—

Returns the not before (nbf) claim as a float representing UNIX time in seconds.


Dictionary get_payload() const ๐Ÿ”—

Returns the entire decoded JWT payload as a dictionary.


String get_signature() const ๐Ÿ”—

Returns the trailing Base64Url-encoded signature portion of the token.


String get_subject() const ๐Ÿ”—

Returns the subject (sub) claim as a String.


bool has_claim(key: String) const ๐Ÿ”—

Returns true if the payload contains the specified claim.


bool has_header_claim(key: String) const ๐Ÿ”—

Returns true if the header contains the specified claim.


bool is_expired() const ๐Ÿ”—

Checks whether the JWT is expired based on the exp claim against the current system time.


void parse(jwt: String) ๐Ÿ”—

Parses the given JWT string and caches its header and payload. Internal use mostly, prefer JWT.parse(jwt).