Permalink
Browse files

feat(authentication): use jwt-decode to decode token

  • Loading branch information...
doktordirk committed May 31, 2016
1 parent fdbb918 commit f5056ce9de726b369f41d57a5fcba38053fdcca9
Showing with 17 additions and 14 deletions.
  1. +5 −0 config.js
  2. +6 −3 package.json
  3. +6 −11 src/authentication.js
@@ -19,6 +19,7 @@ System.config({
"aurelia-router": "npm:aurelia-router@1.0.0-beta.1.2.3",
"extend": "npm:extend@3.0.0",
"fetch": "github:github/fetch@0.11.1",
"jwt-decode": "npm:jwt-decode@2.0.1",
"npm:aurelia-api@3.0.0-rc2": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.1.2.3",
"aurelia-fetch-client": "npm:aurelia-fetch-client@1.0.0-beta.1.2.5",
@@ -52,6 +53,10 @@ System.config({
"aurelia-logging": "npm:aurelia-logging@1.0.0-beta.1.2.1",
"aurelia-path": "npm:aurelia-path@1.0.0-beta.1.2.2",
"aurelia-route-recognizer": "npm:aurelia-route-recognizer@1.0.0-beta.1.2.1"
},
"npm:jwt-decode@2.0.1": {
"fs": "github:jspm/nodelibs-fs@0.1.2",
"systemjs-json": "github:systemjs/plugin-json@0.1.2"
}
}
});
@@ -38,7 +38,8 @@
"aurelia-pal": "^1.0.0-beta.1.2.2",
"aurelia-path": "^1.0.0-beta.1.2.2",
"aurelia-router": "^1.0.0-beta.1.2.3",
"extend": "^3.0.0"
"extend": "^3.0.0",
"jwt-decode": "^2.0.1"
},
"peerDependencies": {
"aurelia-api": "^3.0.0-rc2",
@@ -49,7 +50,8 @@
"aurelia-pal": "^1.0.0-beta.1.2.2",
"aurelia-path": "^1.0.0-beta.1.2.2",
"aurelia-router": "^1.0.0-beta.1.2.3",
"extend": "^3.0.0"
"extend": "^3.0.0",
"jwt-decode": "^2.0.1"
},
"devDependencies": {
"aurelia-pal-browser": "^1.0.0-beta.2.0.1",
@@ -66,7 +68,8 @@
"aurelia-pal": "^1.0.0-beta.1.2.2",
"aurelia-path": "^1.0.0-beta.1.2.2",
"aurelia-router": "^1.0.0-beta.1.2.3",
"extend": "^3.0.0"
"extend": "^3.0.0",
"jwt-decode": "^2.0.1"
},
"devDependencies": {
"aurelia-tools": "^0.1.20",
@@ -1,6 +1,7 @@
import {PLATFORM} from 'aurelia-pal';
import {inject} from 'aurelia-dependency-injection';
import {deprecated} from 'aurelia-metadata';
import jwtDecode from 'jwt-decode';
import * as LogManager from 'aurelia-logging';
import {BaseConfig} from './baseConfig';
@@ -146,19 +147,13 @@ export class Authentication {
}
}
let payload = null;
this.payload = null;
if (this.accessToken && this.accessToken.split('.').length === 3) {
try {
const base64 = this.accessToken.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
payload = JSON.parse(decodeURIComponent(escape(atob(base64))));
} catch (e) {
payload = null;
}
}
try {
this.payload = this.accessToken ? jwtDecode(this.accessToken) : null;
} catch (_) {}
this.payload = payload;
this.exp = payload ? parseInt(payload.exp, 10) : NaN;
this.exp = this.payload ? parseInt(this.payload.exp, 10) : NaN;
this.hasDataStored = true;

0 comments on commit f5056ce

Please sign in to comment.