Angular2-jwt: angular4.3 http interceptor implementation

Created on 15 Jul 2017  ·  12Comments  ·  Source: auth0/angular2-jwt

With Angular 4.3, we now have a HttpInterceptor. This seems like a great place to move the auth handling for Http requests.

Previously in #304 we had raised about replacing the Http module, but I'll close that as using the interceptor would be much less code to maintain and would resolve all issues raised there I believe.

stale

Most helpful comment

I'll be pushing up some work on an alpha which uses an interceptor shortly 👌

All 12 comments

I'll be pushing up some work on an alpha which uses an interceptor shortly 👌

Looking forward to it. Google finally made a decent http client with this new api.

This will be tracked on the v1.0 branch. Not on npm just yet but you can grab the tarball from Github if you like. It's intentionally lean right now but will be brought up to feature parity.

How would one perform HTTP requests without adding the token in this design? Sometimes one needs to do both in an app.

That feature is coming. Most likely it will be through an option set in the request.

Have you had the opportunity to look into this yet? How would one pass a custom option in the request given this signature of HttpClient.request:

```
request(first: string|HttpRequest, url?: string, options: {
body?: any,
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
reportProgress?: boolean,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
}): Observable
````

Where would there be space to pass a JWT option?

@chenkie please consider adding option to exclude certain url's from adding headers.
This way it would be possible to use HttpClient to authenticate user and also do all requests that require authorization header.
Why should we include both components if HttpClient is new and preferred way?

It looks like we might need a URL blacklist option as @achimha is right, we can't pass options in an individual Http request. I'm still looking more into this but I'll add a blacklist option for the next beta to solve it until a more elegant solution is found.

Is there any progress on this issue please?

@chenkie any updates on this? Also Angular 5 is released, so HttpModule is deprecated.

@chenkie thanks for your work on this. With the ability to control the headers and options on a specific request and the ability to add an interceptor this would really be awesome!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leosvelperez picture leosvelperez  ·  5Comments

kolkov picture kolkov  ·  3Comments

n0490b picture n0490b  ·  4Comments

guillaume-skwid picture guillaume-skwid  ·  5Comments

mahendra2125 picture mahendra2125  ·  4Comments