Skip to main content

Class: JWTUtils

Defined in: core/src/JWTUtils.ts:151

Utility class for working with Json Web Token (JWT) authentication tokens.

Constructors​

Constructor​

new JWTUtils(): JWTUtils

Returns​

JWTUtils

Methods​

createToken()​

static createToken(config, user, data?): Promise<string>

Defined in: core/src/JWTUtils.ts:400

Parameters​

config​

JWTUtilsConfig

user​

JWTUser

data?​

any

Returns​

Promise<string>


createTokenSync()​

static createTokenSync(config, user, data?): string

Defined in: core/src/JWTUtils.ts:417

Synchronous counterpart to createToken(). Blocks the event loop while deriving the encryption key when password-based payload encryption is configured (see deriveKeySync) - prefer createToken() on a request-handling path in that case.

Parameters​

config​

JWTUtilsConfig

user​

JWTUser

data?​

any

Returns​

string


decodeToken()​

static decodeToken(config, token): Promise<JWTPayload>

Defined in: core/src/JWTUtils.ts:529

Decodes the given JWT authentication token using the provided configuration. If the token is not valid an error is thrown with the reason. Returns the encoded user object payload upon success.

Parameters​

config​

JWTUtilsConfig

The JWT configuration to use when validating the token.

token​

string

The JWT token to validate.

Returns​

Promise<JWTPayload>

The data encoded in the token's payload.


decodeTokenSync()​

static decodeTokenSync(config, token): JWTPayload

Defined in: core/src/JWTUtils.ts:547

Synchronous counterpart to decodeToken(). Blocks the event loop while deriving the decryption key when password-based payload encryption is configured (see deriveKeySync) - prefer decodeToken() on a request-handling path in that case.

Parameters​

config​

JWTUtilsConfig

The JWT configuration to use when validating the token.

token​

string

The JWT token to validate.

Returns​

JWTPayload

The data encoded in the token's payload.