Skip to content

SudoSOS Back-end API / authentication / TokenHandler

Class: TokenHandler ​

This class is responsible for key management, the signing, validation, and refreshing of JWT.

Constructors ​

Constructor ​

ts
new TokenHandler(options): TokenHandler;

Creates a new token handler instance.

Parameters ​

ParameterTypeDescription
optionsHandlerOptionsthe options to be used by this handler.

Returns ​

TokenHandler

Methods ​

getOptions() ​

ts
getOptions(): HandlerOptions;

Returns ​

HandlerOptions

the options used by this token handler.


refreshToken() ​

ts
refreshToken(token, nonce): Promise<string>;

Refreshes the given token to extend it's expiry time.

Parameters ​

ParameterTypeDescription
tokenstringthe token string to be refreshed.
noncestringthe cryptographically secure nonce to be used.

Returns ​

Promise<string>


signToken() ​

ts
signToken(
   payload, 
   nonce, 
expiry?): Promise<string>;

Creates a token string by signing the payload.

Parameters ​

ParameterTypeDescription
payloadJsonWebTokenthe payload of the JWT.
noncestringthe cryptographically secure nonce to be used.
expiry?numbercustom expiry to override the token default expiry time (in seconds)

Returns ​

Promise<string>


verifyToken() ​

ts
verifyToken(token): Promise<JsonWebToken>;

Verifies if the supplied token string is signed by this handler.

Parameters ​

ParameterTypeDescription
tokenstringthe token string to be validated.

Returns ​

Promise<JsonWebToken>