JSPM

  • Created
  • Published
  • Downloads 2644
  • Score
    100M100P100Q117412F
  • License MIT

Tiny lib for decoding JWTs and verifying signatures, using native crypto APIs

Package Exports

  • @cfworker/jwt
  • @cfworker/jwt/package.json

Readme

cfworker/jwt

Tiny lib for decoding JWTs and verifying signatures, using native crypto APIs.

Currently supports RS256, RS384, and RS512.

const jwt = request.headers.get('Authorization');
const issuer = '...'; // Auth0 origin.
const audience = '...'; // Auth0 client id.

const result = await parseJwt({ jwt, issuer, audience });
if (!result.valid) {
  console.log(result.reason); // Invalid issuer/audience, expired, etc
} else {
  console.log(result.payload); // { iss, sub, aud, iat, exp, ...claims }
}