What is jwt-decode?
The jwt-decode npm package is a small browser library that helps decoding JWTs token which are Base64Url encoded. It is particularly useful for getting the payload or header information out of a JWT token without verifying its signature.
What are jwt-decode's main functionalities?
Decode JWT Token
This feature allows you to decode a JWT token to retrieve the payload and header information. The code sample shows how to use jwt-decode to decode a token and log the decoded payload to the console.
var jwtDecode = require('jwt-decode');
var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ';
var decoded = jwtDecode(token);
console.log(decoded);
Other packages similar to jwt-decode
jsonwebtoken
jsonwebtoken is a popular npm package that not only decodes JWT tokens but also verifies and signs them. It provides a full implementation of JSON Web Tokens, unlike jwt-decode which only decodes tokens without validation.
jws
jws is a JSON Web Signature implementation that allows you to sign, verify, and decode JWTs. It is more feature-rich compared to jwt-decode, which only decodes tokens.
jwt-simple
jwt-simple is another npm package that allows encoding and decoding JWT tokens. It is similar to jwt-decode but also offers the ability to encode tokens, which jwt-decode does not.
jwt-decode is a small browser library that helps decoding JWTs token which are Base64Url encoded.
IMPORTANT: This library doesn't validate the token, any well formed JWT can be decoded. You should validate the token in your server-side logic by using something like express-jwt, koa-jwt, Owin Bearer JWT, etc.
Installation
Install with npm, bower, or downloading from the build directory of this repository.
Use with AMD, browserify or just include with an script tag.
Usage
var token = 'eyJ0eXAiO.../// jwt token';
var decoded = jwt_decode(token);
console.log(decoded);
Note: A falsy token will throw an error.
Can also be used with browserify or webpack by doing npm install jwt-decode
and requiring:
var jwtDecode = require('jwt-decode');
Develop
Run grunt dev
and fire a browser at http://localhost:9999/test_harness.html.
Issue Reporting
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Author
Auth0
License
This project is licensed under the MIT license. See the LICENSE file for more info.