1.0.8 • Published 6 months ago
@practera/jwt-parser v1.0.8
@practera/jwt-parser
Validates a JWT with a public key, parses the token and returns the contents.
Install
$ npm install @practera/jwt-parser
Usage
Notes
exp
object must present in JWT payload when CHECK_JWT_EXPIRY
is enabled (by setting 'true' in string)
Parameters
CHECK_JWT_EXPIRY
- will invalidate a JWT when the expiry timestamp (in seconds) isn't provided.
How to use?
JavaScript:
const jwtParse = require("@practera/jwt-parser");
jwtContents = jwtParse(
token, // the token to be verified and parsed
process.env, // environmental variables or another array of tokens that are accepted
service, // this will identify what public key to use to validate the token, the variable called ${service}_JWT will be used. The variable should contain a key called public and the public key as the value.
['RS256'], // list of algorithms that will be used to validate the token. Default: ['RS256']
);
TypeScript:
import jwtParse from "@practera/jwt-parser";
jwtContents = jwtParse(
token, // the token to be verified and parsed
process.env, // environmental variables or another array of tokens that are accepted
service, // this will identify what public key to use to validate the token, the variable called ${service}_JWT will be used. The variable should contain a key called public and the public key as the value.
['RS256'], // list of algorithms that will be used to validate the token. Default: ['RS256']
);