GithubHelp home page GithubHelp logo

mrtrieu69 / jwt-decode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from auth0/jwt-decode

0.0 0.0 0.0 212 KB

Decode JWT tokens; useful for browser applications.

License: MIT License

JavaScript 92.39% HTML 7.61%

jwt-decode's Introduction

Browser library that helps decoding JWT tokens 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.

Release Downloads License CircleCI

๐Ÿ“š Documentation - ๐Ÿš€ Getting Started - ๐Ÿ’ฌ Feedback

Documentation

  • Docs site - explore our docs site and learn more about Auth0.

Getting started

Installation

Install with NPM or Yarn.

Run npm install jwt-decode or yarn add jwt-decode to install the library.

Usage

import jwt_decode from "jwt-decode";

var token = "eyJ0eXAiO.../// jwt token";
var decoded = jwt_decode(token);

console.log(decoded);

/* prints:
 * { 
 *   foo: "bar",
 *   exp: 1393286893,
 *   iat: 1393268893  
 * }
 */

// decode header by passing in options (useful for when you need `kid` to verify a JWT):
var decodedHeader = jwt_decode(token, { header: true });
console.log(decodedHeader);

/* prints:
 * { 
 *   typ: "JWT",
 *   alg: "HS256" 
 * }
 */

Note: A falsy or malformed token will throw an InvalidTokenError error.

Use with typescript

The jwt_decode function will return an unknown type by default. You can specify what the expected return type should be by passing a type argument to the jwt_decode function.

The package also exports types for a JwtHeader and JwtPayload with some default claims. You can either use them as-is, or extend them to include non standard claims or properties.

import jwtDecode, { JwtPayload } from "jwt-decode";

const token: string = "eyJhsw5c";
const decoded = jwtDecode<JwtPayload>(token); // Returns with the JwtPayload type

Use as a CommonJS package

const jwt_decode = require('jwt-decode');
...

Include with a script tag

Copy the file jwt-decode.js from the build/ folder to your project somewhere, then include like so:

<script src="jwt-decode.js"></script>

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

jwt-decode's People

Contributors

alex-sokolov avatar ashaffer avatar bmatcuk avatar cesargdm avatar damieng avatar dschaller avatar euharrison avatar evansims avatar frederikprijck avatar gurbraj avatar janimakinen avatar jfromaniello avatar jimmyjames avatar joshcanhelp avatar kkirsche avatar lbalmaceda avatar mattkrick avatar mkazlauskas avatar ntotten avatar pose avatar remcohaszing avatar sambego avatar sdoxsee avatar thisisjohnwill avatar tlvince avatar tschaub avatar vvakame avatar widcket avatar xmlmxmlmx avatar zackharley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.