Skip to content

Commit

Permalink
add version note and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkie committed Mar 10, 2018
1 parent c95ca36 commit 44fed3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @auth0/angular-jwt

### **NOTE:** This library is now at version 1.0 and is published on npm as `@auth0/angular-jwt`. If you're looking for the pre-v1.0 version of this library, it can be found in the `pre-v1.0` branch and on npm as `angular2-jwt`.

This library provides an `HttpInterceptor` which automatically attaches a [JSON Web Token](https://jwt.io) to `HttpClient` requests.

This library does not have any functionality for (or opinion about) implementing user authentication and retrieving JWTs to begin with. Those details will vary depending on your setup, but in most cases, you will use a regular HTTP request to authenticate your users and then save their JWTs in local storage or in a cookie if successful.
Expand Down Expand Up @@ -34,7 +36,6 @@ const expirationDate = helper.getTokenExpirationDate(myRawToken);
const isExpired = helper.isTokenExpired(myRawToken);
```


## Usage: Injection

Import the `JwtModule` module and add it to your imports list. Call the `forRoot` method and provide a `tokenGetter` function. You must also whitelist any domains that you want to make requests to by specifying a `whitelistedDomains` array.
Expand Down Expand Up @@ -72,17 +73,13 @@ Any requests sent using Angular's `HttpClient` will automatically have a token a
import { HttpClient } from '@angular/common/http';

export class AppComponent {

constructor(public http: HttpClient) {}

ping() {
this.http.get('http://example.com/api/things')
.subscribe(
data => console.log(data),
err => console.log(err)
);
this.http
.get('http://example.com/api/things')
.subscribe(data => console.log(data), err => console.log(err));
}

}
```

Expand All @@ -101,7 +98,7 @@ JwtModule.forRoot({
return localStorage.getItem('access_token');
}
}
})
});
```

### `whitelistedDomains: array`
Expand All @@ -117,23 +114,22 @@ JwtModule.forRoot({
// ...
whitelistedDomains: ['localhost:3001', 'foo.com', 'bar.com']
}
})
});
```

### `blacklistedRoutes: array`

If you do not want to replace the authorization headers for specific routes, list them here. This can be useful if your
initial auth route(s) are on a whitelisted domain and take basic auth headers.


```ts
// ...
JwtModule.forRoot({
config: {
// ...
blacklistedRoutes: ['localhost:3001/auth/', 'foo.com/bar/']
}
})
});
```

**Note:** If requests are sent to the same domain that is serving your Angular application, you do not need to add that domain to the `whitelistedDomains` array. However, this is only the case if you don't specify the domain in the `Http` request.
Expand Down Expand Up @@ -166,22 +162,21 @@ JwtModule.forRoot({
// ...
headerName: 'Your Header Name'
}
})
});
```

### `authScheme: string`

The default authorization scheme is `Bearer` followed by a single space. This can be changed by specifying a custom `authScheme` which is to be a string.


```ts
// ...
JwtModule.forRoot({
config: {
// ...
authScheme: 'Your Auth Scheme'
}
})
});
```

### `throwNoTokenError: boolean`
Expand All @@ -195,7 +190,7 @@ JwtModule.forRoot({
// ...
throwNoTokenError: true
}
})
});
```

### `skipWhenExpired: boolean`
Expand All @@ -209,7 +204,7 @@ JwtModule.forRoot({
// ...
skipWhenExpired: true
}
})
});
```

## Using a Custom Options Factory Function
Expand All @@ -220,7 +215,6 @@ Import the `JWT_OPTIONS` `InjectionToken` so that you can instruct it to use you

Create a factory function and specify the options as you normally would if you were using `JwtModule.forRoot` directly. If you need to use a service in the function, list it as a parameter in the function and pass it in the `deps` array when you provide the function.


```ts
import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt';
import { TokenService } from './app.tokenservice';
Expand Down Expand Up @@ -252,7 +246,7 @@ export function jwtOptionsFactory(tokenService) {
})
```

NOTE: If a `jwtOptionsFactory` is defined, then `config` is ignored. *Both configuration alternatives can't be defined at the same time*.
NOTE: If a `jwtOptionsFactory` is defined, then `config` is ignored. _Both configuration alternatives can't be defined at the same time_.

## Configuration for Ionic 2+

Expand Down Expand Up @@ -291,8 +285,9 @@ export function jwtOptionsFactory(storage) {
### `JwtHelperService: service`

This service contains helper functions:

## isTokenExpired (old tokenNotExpired function)

```
import { JwtHelperService } from '@auth0/angular-jwt';
// ...
Expand All @@ -302,8 +297,9 @@ ngOnInit() {
console.log(this.jwtHelper.isTokenExpired()); // true or false
}
```

## getTokenExpirationDate

```
import { JwtHelperService } from '@auth0/angular-jwt';
// ...
Expand All @@ -315,6 +311,7 @@ console.log(this.jwtHelper.getTokenExpirationDate()); // date
```

## decodeToken

```
import { JwtHelperService } from '@auth0/angular-jwt';
// ...
Expand All @@ -338,8 +335,8 @@ Auth0 helps you to:

## Create a free Auth0 account

1. Go to [Auth0](https://auth0.com/signup) and click Sign Up.
2. Use Google, GitHub or Microsoft Account to login.
1. Go to [Auth0](https://auth0.com/signup) and click Sign Up.
2. Use Google, GitHub or Microsoft Account to login.

## Issue Reporting

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": "@auth0/angular-jwt",
"version": "1.0.0-beta.11",
"version": "1.0.0",
"description": "JSON Web Token helper library for Angular",
"scripts": {
"prepublish": "ngc && npm run build",
Expand Down

0 comments on commit 44fed3b

Please sign in to comment.