Added refresh token functionality

This commit is contained in:
Giuseppe Digilio
2018-02-26 15:41:07 +01:00
parent 2637f1c28e
commit 696b8b73f5
22 changed files with 301 additions and 114 deletions

View File

@@ -1,13 +1,15 @@
import { default as decode } from 'jwt-decode';
export const TOKENITEM = 'dsAuthInfo';
export class AuthTokenInfo {
public accessToken: string;
public expires?: number;
public expires: number;
constructor(token: string, expiresIn?: number) {
constructor(token: string) {
this.accessToken = token.replace('Bearer ', '');
if (expiresIn) {
this.expires = expiresIn * 1000 + Date.now();
}
const tokenClaims = decode(this.accessToken);
// exp claim is in seconds, convert it se to milliseconds
this.expires = tokenClaims.exp * 1000;
}
}