jwt-claims

Minimal utility for decoding JWT claims

Usage no npm install needed!

<script type="module">
  import jwtClaims from 'https://cdn.skypack.dev/jwt-claims';
</script>

README

jwt-claims

Parse claims from a JWT payload.

npm install jwt-claims

Example:

var decode = require('jwt-claims');

var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.' +
    'eyJuYW1lIjoi0JvQtdC-0L3RgtC40LkiLCJudW0iOjQyLCJib29sIjpmYWxzZX0.' +
    'icqeYQUXd1l84wHc-vIzVXOQx7DI4V2H-YV34su7cuY';

var claims = decode(token);

console.log(claims);
// { name: 'Леонтий', num: 42, bool: false }

Note that parsing the claims from a JWT payload does not mean that the token is valid. You can use something like jwt-simple to create new tokens and validate existing ones. This module is meant to be used in places where you don't want to share the secret used to mint the token (e.g. a browser).

The jwt-claims package works in Node and browsers using a CommonJS module loader (e.g. Browserify or Webpack). Tested on Node 0.12, Chrome, Firefox, and IE 11.

Current Status