0.0.8 • Published 5 years ago

jwks-client-browser v0.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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!

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago