@oslojs/jwt
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@oslojs/jwt

Documentation: https://jwt.oslojs.dev

A JavaScript library for parsing and encoding JSON web tokens (JWT) by Oslo. Only signed tokens are supported.

  • Runtime-agnostic
  • No third-party dependencies
  • Fully typed
import { parseJWT, JWSRegisteredHeaders, JWTRegisteredClaims, joseAlgorithmHS256 } from "@oslojs/jwt";

const [header, payload, signature] = parseJWT(jwt);
const headerParameters = new JWSRegisteredHeaders(header);
if (header.algorithm() !== joseAlgorithmHS256) {
	throw new Error("Unsupported algorithm");
}
const claims = new JWTRegisteredClaims(payload);
if (!claims.verifyExpiration()) {
	throw new Error("Expired token");
}
if (claims.hasNotBefore() && !claims.verifyNotBefore()) {
	throw new Error("Invalid token");
}

Installation

npm i @oslojs/jwt

Readme

Keywords

Package Sidebar

Install

npm i @oslojs/jwt

Weekly Downloads

9,719

Version

0.3.0

License

MIT

Unpacked Size

15.3 kB

Total Files

5

Last publish

Collaborators

  • pilcrowonpaper