Skip to content

Commit

Permalink
update token name
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkie committed Apr 11, 2017
1 parent 7bf4847 commit a6984d1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class App {

* Header Name: `Authorization`
* Header Prefix: `Bearer`
* Token Name: `access_token`
* Token Name: `token`
* Token Getter Function: `(() => localStorage.getItem(tokenName))`
* Supress error and continue with regular HTTP request if no JWT is saved: `false`
* Global Headers: none
Expand Down Expand Up @@ -181,7 +181,7 @@ export function getAuthHttp(http) {
headerPrefix: YOUR_HEADER_PREFIX,
noJwtError: true,
globalHeaders: [{'Accept': 'application/json'}],
tokenGetter: (() => storage.get('access_token')),
tokenGetter: (() => storage.get('token')),
}), http);
}

Expand Down Expand Up @@ -258,7 +258,7 @@ You can use these methods by passing in the token to be evaluated.
jwtHelper: JwtHelper = new JwtHelper();

useJwtHelper() {
var token = localStorage.getItem('access_token');
var token = localStorage.getItem('token');

console.log(
this.jwtHelper.decodeToken(token),
Expand All @@ -273,7 +273,7 @@ useJwtHelper() {
The `tokenNotExpired` function can be used to check whether a JWT exists in local storage, and if it does, whether it has expired or not. If the token is valid, `tokenNotExpired` returns `true`, otherwise it returns `false`.
> **Note:** `tokenNotExpired` will by default assume the token name is `access_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`.
> **Note:** `tokenNotExpired` will by default assume the token name is `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`.
```ts
// auth.service.ts
Expand Down
6 changes: 3 additions & 3 deletions angular2-jwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('AuthConfig', ()=> {
expect(config).toBeDefined();
expect(config.headerName).toBe("Authorization");
expect(config.headerPrefix).toBe("Bearer ");
expect(config.tokenName).toBe("access_token");
expect(config.tokenName).toBe("token");
expect(config.noJwtError).toBe(false);
expect(config.noTokenScheme).toBe(false);
expect(config.globalHeaders).toEqual([]);
Expand Down Expand Up @@ -162,12 +162,12 @@ describe('tokenNotExpired', ()=> {
expect(actual).toBe(false);
});
it('should use the defaults when not expired', ()=> {
localStorage.setItem("access_token", validToken);
localStorage.setItem("token", validToken);
const actual:boolean=tokenNotExpired();
expect(actual).toBe(true);
});
it('should use the defaults when expired', ()=> {
localStorage.setItem("access_token", expiredToken);
localStorage.setItem("token", expiredToken);
const actual:boolean=tokenNotExpired();
expect(actual).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion angular2-jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface IAuthConfigOptional {
}

export class AuthConfigConsts {
public static DEFAULT_TOKEN_NAME = 'access_token';
public static DEFAULT_TOKEN_NAME = 'token';
public static DEFAULT_HEADER_NAME = 'Authorization';
public static HEADER_PREFIX_BEARER = 'Bearer ';
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-jwt",
"version": "0.2.1",
"version": "0.2.2",
"description": "Helper library for handling JWTs in Angular 2+",
"repository": {
"type": "git",
Expand Down

0 comments on commit a6984d1

Please sign in to comment.