angular2-jwt
Advanced tools
Comparing version 0.1.15 to 0.1.16
@@ -10,2 +10,3 @@ import { Http, Request, RequestOptionsArgs, Response } from '@angular/http'; | ||
globalHeaders: Array<Object>; | ||
noTokenScheme?: boolean; | ||
} | ||
@@ -16,3 +17,2 @@ /** | ||
export declare class AuthConfig { | ||
config: any; | ||
headerName: string; | ||
@@ -26,11 +26,3 @@ headerPrefix: string; | ||
constructor(config?: any); | ||
getConfig(): { | ||
headerName: string; | ||
headerPrefix: string; | ||
tokenName: string; | ||
tokenGetter: any; | ||
noJwtError: boolean; | ||
emptyHeaderPrefix: boolean; | ||
globalHeaders: Object[]; | ||
}; | ||
getConfig(): IAuthConfig; | ||
} | ||
@@ -37,0 +29,0 @@ /** |
@@ -20,8 +20,8 @@ "use strict"; | ||
var _this = this; | ||
this.config = config || {}; | ||
this.headerName = this.config.headerName || 'Authorization'; | ||
if (this.config.headerPrefix) { | ||
this.headerPrefix = this.config.headerPrefix + ' '; | ||
if (config === void 0) { config = {}; } | ||
this.headerName = config.headerName || 'Authorization'; | ||
if (config.headerPrefix) { | ||
this.headerPrefix = config.headerPrefix + ' '; | ||
} | ||
else if (this.config.noTokenScheme) { | ||
else if (config.noTokenScheme) { | ||
this.headerPrefix = ''; | ||
@@ -32,6 +32,7 @@ } | ||
} | ||
this.tokenName = this.config.tokenName || 'id_token'; | ||
this.noJwtError = this.config.noJwtError || false; | ||
this.tokenGetter = this.config.tokenGetter || (function () { return localStorage.getItem(_this.tokenName); }); | ||
this.globalHeaders = this.config.globalHeaders || null; | ||
this.tokenName = config.tokenName || 'id_token'; | ||
this.noJwtError = config.noJwtError || false; | ||
this.tokenGetter = config.tokenGetter || (function () { return localStorage.getItem(_this.tokenName); }); | ||
this.globalHeaders = config.globalHeaders || []; | ||
this.noTokenScheme = config.noTokenScheme || false; | ||
} | ||
@@ -45,3 +46,3 @@ AuthConfig.prototype.getConfig = function () { | ||
noJwtError: this.noJwtError, | ||
emptyHeaderPrefix: this.noTokenScheme, | ||
noTokenScheme: this.noTokenScheme, | ||
globalHeaders: this.globalHeaders | ||
@@ -165,3 +166,3 @@ }; | ||
} | ||
return decodeURIComponent(escape(window.atob(output))); //polifyll https://github.com/davidchambers/Base64.js | ||
return decodeURIComponent(escape(window.atob(output))); //polyfill https://github.com/davidchambers/Base64.js | ||
}; | ||
@@ -206,17 +207,6 @@ JwtHelper.prototype.decodeToken = function (token) { | ||
function tokenNotExpired(tokenName, jwt) { | ||
var authToken = tokenName || 'id_token'; | ||
var token; | ||
if (jwt) { | ||
token = jwt; | ||
} | ||
else { | ||
token = localStorage.getItem(authToken); | ||
} | ||
if (tokenName === void 0) { tokenName = 'id_token'; } | ||
var token = jwt || localStorage.getItem(tokenName); | ||
var jwtHelper = new JwtHelper(); | ||
if (!token || jwtHelper.isTokenExpired(token, null)) { | ||
return false; | ||
} | ||
else { | ||
return true; | ||
} | ||
return token && !jwtHelper.isTokenExpired(token, null); | ||
} | ||
@@ -223,0 +213,0 @@ exports.tokenNotExpired = tokenNotExpired; |
@@ -15,2 +15,3 @@ import {provide, Injectable} from '@angular/core'; | ||
globalHeaders: Array<Object>; | ||
noTokenScheme?:boolean; | ||
} | ||
@@ -24,3 +25,2 @@ | ||
config: any; | ||
headerName: string; | ||
@@ -34,8 +34,7 @@ headerPrefix: string; | ||
constructor(config?: any) { | ||
this.config = config || {}; | ||
this.headerName = this.config.headerName || 'Authorization'; | ||
if (this.config.headerPrefix) { | ||
this.headerPrefix = this.config.headerPrefix + ' '; | ||
} else if (this.config.noTokenScheme) { | ||
constructor(config:any={}) { | ||
this.headerName = config.headerName || 'Authorization'; | ||
if (config.headerPrefix) { | ||
this.headerPrefix = config.headerPrefix + ' '; | ||
} else if (config.noTokenScheme) { | ||
this.headerPrefix = ''; | ||
@@ -45,9 +44,10 @@ } else { | ||
} | ||
this.tokenName = this.config.tokenName || 'id_token'; | ||
this.noJwtError = this.config.noJwtError || false; | ||
this.tokenGetter = this.config.tokenGetter || (() => localStorage.getItem(this.tokenName)); | ||
this.globalHeaders = this.config.globalHeaders || null; | ||
this.tokenName = config.tokenName || 'id_token'; | ||
this.noJwtError = config.noJwtError || false; | ||
this.tokenGetter = config.tokenGetter || (() => localStorage.getItem(this.tokenName)); | ||
this.globalHeaders = config.globalHeaders || []; | ||
this.noTokenScheme=config.noTokenScheme||false; | ||
} | ||
getConfig() { | ||
getConfig():IAuthConfig { | ||
return { | ||
@@ -59,3 +59,3 @@ headerName: this.headerName, | ||
noJwtError: this.noJwtError, | ||
emptyHeaderPrefix: this.noTokenScheme, | ||
noTokenScheme:this.noTokenScheme, | ||
globalHeaders: this.globalHeaders | ||
@@ -192,3 +192,3 @@ } | ||
return decodeURIComponent(escape(window.atob(output))); //polifyll https://github.com/davidchambers/Base64.js | ||
return decodeURIComponent(escape(window.atob(output))); //polyfill https://github.com/davidchambers/Base64.js | ||
} | ||
@@ -242,23 +242,9 @@ | ||
export function tokenNotExpired(tokenName?:string, jwt?:string) { | ||
export function tokenNotExpired(tokenName = 'id_token', jwt?:string):boolean { | ||
var authToken:string = tokenName || 'id_token'; | ||
var token:string; | ||
const token:string = jwt || localStorage.getItem(tokenName); | ||
if(jwt) { | ||
token = jwt; | ||
} | ||
else { | ||
token = localStorage.getItem(authToken); | ||
} | ||
const jwtHelper = new JwtHelper(); | ||
var jwtHelper = new JwtHelper(); | ||
if(!token || jwtHelper.isTokenExpired(token, null)) { | ||
return false; | ||
} | ||
else { | ||
return true; | ||
} | ||
return token && !jwtHelper.isTokenExpired(token, null); | ||
} | ||
@@ -273,2 +259,2 @@ | ||
}) | ||
]; | ||
]; |
{ | ||
"name": "angular2-jwt", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"description": "Helper library for handling JWTs in Angular 2", | ||
@@ -11,2 +11,3 @@ "repository": { | ||
"dev": "tsc --watch", | ||
"test": "karma start", | ||
"prepublish": "typings install && tsc" | ||
@@ -31,3 +32,13 @@ }, | ||
"@angular/http": "^2.0.0-rc.1", | ||
"awesome-typescript-loader": "^0.17.0", | ||
"core-js": "^2.3.0", | ||
"es6-shim": "^0.35.0", | ||
"jasmine-core": "^2.4.1", | ||
"karma": "^0.13.22", | ||
"karma-chrome-launcher": "^0.2.3", | ||
"karma-jasmine": "^0.3.8", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^1.7.0", | ||
"phantomjs-prebuilt": "^2.1.7", | ||
"reflect-metadata": "0.1.2", | ||
@@ -37,2 +48,3 @@ "rxjs": "5.0.0-beta.6", | ||
"typings": "^0.7.12", | ||
"webpack": "^1.13.0", | ||
"zone.js": "~0.6.12" | ||
@@ -39,0 +51,0 @@ }, |
@@ -52,3 +52,3 @@ # angular2-jwt [![npm version](https://img.shields.io/npm/v/angular2-jwt.svg)](https://www.npmjs.com/package/angular2-jwt) [![license](https://img.shields.io/npm/l/angular2-jwt.svg)](https://www.npmjs.com/package/angular2-jwt) | ||
data => this.thing = data, | ||
err => console.log(error), | ||
err => console.log(err), | ||
() => console.log('Request Complete') | ||
@@ -195,2 +195,4 @@ ); | ||
> **NOTE**: The `@CanActivate` lifecycle hook has been deprecated in the latest Angular 2 router. To use it, you need to `import` from `@angular/router-deprecated`. | ||
> **Note:** `tokenNotExpired` will by default assume the token name is `id_token` unless a token name is passed to it, ex: `tokenNotExpired('token_name')`. This will be changed in a future release to automatically use the token name that is set in `AuthConfig`. | ||
@@ -197,0 +199,0 @@ |
{ | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"ambientDependencies": { | ||
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2" | ||
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2", | ||
"jasmine": "registry:dt/jasmine#2.2.0+20160412134438" | ||
} | ||
} |
/// <reference path="browser/ambient/es6-shim/index.d.ts" /> | ||
/// <reference path="browser/ambient/jasmine/index.d.ts" /> |
/// <reference path="main/ambient/es6-shim/index.d.ts" /> | ||
/// <reference path="main/ambient/jasmine/index.d.ts" /> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128197
17
2591
252
19