aurelia-plugins-jwt-decode
TypeScript icon, indicating that this package has built-in type declarations

2.6.0 • Public • Published

aurelia-plugins-jwt-decode

A JWT Decode plugin for Aurelia.

This plugin uses jwt-decode from Auth0 under the hood.

Installation

Webpack/Aurelia CLI

npm install aurelia-plugins-jwt-decode --save

When using Aurelia CLI add the following dependency to aurelia.json:

{
  "name": "aurelia-plugins-jwt-decode",
  "path": "../node_modules/aurelia-plugins-jwt-decode/dist/amd",
  "main": "aurelia-plugins-jwt-decode"
}

Add node_modules/babel-polyfill/dist/polyfill.min.js to the prepend list in aurelia.json. Do not forgot to add babel-polyfill to the dependencies in package.json.

JSPM

jspm install aurelia-plugins-jwt-decode

Bower

bower install aurelia-plugins-jwt-decode

Configuration

It is not necessary to load the plugin inside of the configure method of your main.js or main.ts, because this plugin doesn't use any dependencies of Aurelia. The only thing you need to be sure of, is that the library is loaded in your project.

Usage

The plugin is used as a class with static methods. No dependency injection is necessary. Just import it in your own class.

The following method is provided:

import {JwtDecode} from 'aurelia-plugins-jwt-decode';
 
export class App {
  // Returns the deserialized value (object) of the given token
  JwtDecode.decode(token, [options]);
}

Options

Header

A boolean indicating if the header part of the JWT is not present. By default the header option is false, and present.

This example uses the default option because the token contains besides the payload also the header and the signature.

const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ';
 
JwtDecode.decode(token);

The following example has a token which only contains a payload. Use the option header: true to decode the token which has no header.

const token = 'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9';
 
JwtDecode.decode(token, { header: true });

Package Sidebar

Install

npm i aurelia-plugins-jwt-decode

Weekly Downloads

154

Version

2.6.0

License

MIT

Unpacked Size

110 kB

Total Files

18

Last publish

Collaborators