1.0.0 • Published 4 years ago
@janiscommerce/jwt v1.0.0
jwt
A helper to verify Janis JWTs
Installation
npm install @janiscommerce/jwt
API
JWT
This is the main exported class. It has only one public method: async verifyToken(token)
. This method will resolve the decoded token payload, or reject in case of error.
Configuration
By default this package will handle JWKs properly, but you can configure a custom JWKS URI in case you want to test a different environment.
Precedence
- An options object with a
jwksUri
property when you instanciate JWT Class. - An environment variable named
JANISCOMMERCE_JWT_JWKS_URI
- Defaults to Janis ID Production URI
Usage
const { JWT } = require('@janiscommerce/jwt');
// Default behaviour, decodes with Janis Production JWKS URI
const jwt = new JWT();
const decodedToken = await jwt.verifyToken(token);
// Override default with an env var
process.env.JANISCOMMERCE_JWT_JWKS_URI = 'https://example.com/.well-known/jwks.json';
const envJwt = new JWT();
const envDecodedToken = await envJwt.verifyToken(token);
// Override by passing jwksUri option
const withOptionJwt = new JWT({
jwksUri: 'https://override.com/.well-known/jwks.json'
});
const withOptionDecodedToken = await withOptionJwt.verifyToken(token);
1.0.0
4 years ago