0.0.8 • Published 6 years ago
jwks-client-browser v0.0.8
jwks-client-browser 
This pacakge was created, because the current JWKS clients available only work in node, but not in the browser. This client is specifically designed to work in the browser. Given a JWKS endpoint URL and a kid it will retrieve the public key that you can use for JWT verification.
Installation
npm i jwks-client-browseror
yarn add jwks-client-browserUsage
JavaScript
import JwksClient from 'jwks-client-browser';
const kid = JSON.parse(atob(token.split('.')[0])).kid
const jwksClient = new JwksClient({ url: '[your_jwks_endpoint]' });
const signingKey = jwksClient.getSigningKey(kid);TypeScript
import JwksClient, { ISigningKeyPem } from 'jwks-client-browser';
const kid: string = JSON.parse(atob(token.split('.')[0])).kid
const jwksClient: JwksClient = new JwksClient({ url: '[your_jwks_endpoint]' });
const signingKey: ISigningKeyPem = jwksClient.getSigningKey(kid);Once you acquired the public key, you can use it to verify the token. Here's an example using the jsonwebtoken package:
import jwt from 'jsonwebtoken';
const signingKey: ISigningKeyPem = jwksClient.getSigningKey(kid);
jwt.verify(token, signingKey.publicKey);Disclaimer
This is still a draft version of the package. Contributions are welcome!