Class: JWTUtils#

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

author Jean-Philippe Steinmetz info@acceleratxr.com

Hierarchy#

  • JWTUtils

Index#

Methods#

Methods#

createToken#

StaticcreateToken(config: JWTUtilsConfig, user: JWTUser): string

Defined in src/utils/JWTUtils.ts:156

Generates a new JWT token for the given config and user object. The user object must be a valid AcceleratXR user.

Parameters:#

Name

Type

Description

config

JWTUtilsConfig

The JWT configuration to use when generating the token.

user

JWTUser

The user to encode into the token’s payload.

Returns: string


decodeToken#

StaticdecodeToken(token: string, config?: JWTUtilsConfig): JWTUser

Defined in src/utils/JWTUtils.ts:206

Decodes the given JWT authentication token using the provided configuration. This does not verify the authenticity of the token. To verify a token is valid use verifyToken instead.

Parameters:#

Name

Type

Description

token

string

The JWT token to decode.

config?

JWTUtilsConfig

The optional JWTUtils configuration to use when decoding. This is required if payload encryption or compression is utilized.

Returns: JWTUser

The user object encoded in the token’s payload.


verifyToken#

StaticverifyToken(config: JWTUtilsConfig, token: string): JWTUser

Defined in src/utils/JWTUtils.ts:251

Verifies 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:#

Name

Type

Description

config

JWTUtilsConfig

The JWT configuration to use when validating the token.

token

string

The JWT token to validate.

Returns: JWTUser

The user object encoded in the token’s payload.