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 ​
| Parameter | Type | Description |
|---|---|---|
options | HandlerOptions | the options to be used by this handler. |
Returns ​
TokenHandler
Methods ​
getOptions() ​
ts
getOptions(): HandlerOptions;Returns ​
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 ​
| Parameter | Type | Description |
|---|---|---|
token | string | the token string to be refreshed. |
nonce | string | the 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 ​
| Parameter | Type | Description |
|---|---|---|
payload | JsonWebToken | the payload of the JWT. |
nonce | string | the cryptographically secure nonce to be used. |
expiry? | number | custom 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 ​
| Parameter | Type | Description |
|---|---|---|
token | string | the token string to be validated. |
Returns ​
Promise<JsonWebToken>