jwks-client-browser
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

jwks-client-browser npm

CircleCI codecov Dependencies install size npm downloads Known Vulnerabilities NPM

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-browser

or

yarn add jwks-client-browser

Usage

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!

Package Sidebar

Install

npm i jwks-client-browser

Weekly Downloads

1

Version

0.0.8

License

MIT

Unpacked Size

11.6 kB

Total Files

5

Last publish

Collaborators

  • sleepingevil