angular2-interceptors icon indicating copy to clipboard operation
angular2-interceptors copied to clipboard

Add an example for retry

Open prog110 opened this issue 8 years ago • 2 comments

Can u add an example to the readme on how to do retry. For eg., in OAuth2, when a request is made, if the auth token has expired, the client (browser) needs to refresh auth token using refresh token & make a new request for the previous failed call using this new auth token

If for some reason, both auth & refresh tokens are expired, the user needs to be sent to login page.

Can you update the documentation to reflects flows of this nature

prog110 avatar Jan 04 '17 05:01 prog110

Here is the complete OAuth2 flow

OAuth2 refresh token flow

prog110 avatar Jan 04 '17 06:01 prog110

Sure, I'll try to put an example to describe this case, as it's quite complex.

I'll think more about it when I have more time, but I think the way to go is that all this flow is managed by an interceptor, call him "AuthInterceptor". Then in interceptAfter (where we get the response from the server) we can check for OAuth token expired. If it has, then we can send another request from the same interceptor to renew the token, because we can actually return a Observable<InterceptedResponse> on interceptAfter, allowing us to do async stuff inside.

I still have to create some usage examples, and this one looks great to start with.

voliva avatar Jan 09 '17 13:01 voliva