Skip to content

Commit

Permalink
Update the docs to show the injected HttpRequest in the token getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sambego committed May 6, 2020
1 parent 3bc2be4 commit a04c2c2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class AppComponent {

## Configuration Options

### `tokenGetter: function`
### `tokenGetter: function(?HttpRequest)`

The `tokenGetter` is a function which returns the user's token. This function simply needs to make a retrieval call to wherever the token is stored. In many cases, the token will be stored in local storage or session storage.

Expand All @@ -104,6 +104,24 @@ JwtModule.forRoot({
});
```

If you have multiple tokens for multiple domains, you can use the `HttpRequest` passed to the `tokenGetter` function to get the correct token for each intercepted request.

```ts
// ...
JwtModule.forRoot({
config: {
// ...
tokenGetter: (request) => {
if (request.url.includes("foo")) {
return localStorage.getItem("access_token_foo");
}

return localStorage.getItem("access_token");
},
},
});
```

### `whitelistedDomains: array`

Authenticated requests should only be sent to domains you know and trust. Many applications make requests to APIs from multiple domains, some of which are not controlled by the developer. Since there is no way to know what the API being called will do with the information contained in the request, it is best to not send the user's token to all APIs in a blind fashion.
Expand Down

0 comments on commit a04c2c2

Please sign in to comment.