Skip to content

Repository files navigation

@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);constheaderParameters=newJWSRegisteredHeaders(header);if(headerParameters.algorithm()!==joseAlgorithmHS256){thrownewError("Unsupported algorithm");}constclaims=newJWTRegisteredClaims(payload);if(!claims.verifyExpiration()){thrownewError("Expired token");}if(claims.hasNotBefore()&&!claims.verifyNotBefore()){thrownewError("Invalid token");}

Installation

npm i @oslojs/jwt

About

Parse and encode JSON web tokens

Resources

Contributing

Stars

173 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages