Skip to content

Library not handling 401 error response? #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michaelbazos opened this issue Sep 19, 2018 · 6 comments
Closed

Library not handling 401 error response? #429

michaelbazos opened this issue Sep 19, 2018 · 6 comments

Comments

@michaelbazos
Copy link

Hi,

I was reading the part related to interceptors in the documentation, which states:

Since 3.1 the library uses a default HttpInterceptor that takes care about transmitting the access_token to the resource server and about error handling for security related errors (HTTP status codes 401 and 403) received from the resource server.

Reading at the library code version 4+ (4.0.2 to be precise), I can see that the Authorization header is sent, providing that the flag sendAccessToken is set, however I don't see any handling of the "401 Unauthorized" http response.

Can anyone shed some light? Maybe I'm missing something?

@jeroenheijmans
Copy link
Collaborator

jeroenheijmans commented Sep 19, 2018

The library has no logic at all for retry policies, or for redirecting on 401/403 (or anything related). The only interceptor provided by the lib itself is one to append the Authorization: Bearer ... header to requests made to the Resource (API) Server.

You can also check my earlier issue, #414, about the same topic. Perhaps this issue is even a duplicate?

In the end, it would probably make sense to have the application decide how to handle 401/403 errors though, given that there's many different possible options (do nothing, show a dialog, redirect users to log in, only try silent refresh, etc.).

@michaelbazos
Copy link
Author

michaelbazos commented Sep 19, 2018

Thanks for looking into it @jeroenheijmans

I noticed #414, it is related, but different in the sense that it is more about hooking custom logic, like retries, on error responses.

I went to open this question-issue as I was confused by the statement that the library does handle 401 and 403.

Not that it is hard to write an interceptor in the application itself, but I think it makes sense that the library redirects by default to login on 401 errors, and that it allows this behavior to be overridden.

@jeroenheijmans
Copy link
Collaborator

Hah, good points. I clarified the other issue as well.

The retries mentioned there are secondary, the actual important thing is logging the user in (silently, if possible). Same as your intention, I still think? It's just that you seem to prefer what I called "Option 4", making the login upon 401/403 (and retry if the login was done silently), whereas I think it's an application concern and thus lean to "Option 1".

In any case, I would agree that the current documentation you quoted is not appropriate. Possibly the original author intended to suggest that 401s/403s are "prevented" by the default interceptor provided by the library, which is the case.

So in any case, I'm all for changing that bit of documentation to match current library behavior.

I'm not so sure if I'm fore "Option 4" / having the library redirec on 401s (certainly not by default), since those flows can vary greatly between applications.

@michaelbazos
Copy link
Author

I see. So the 401 / 403 that would occur because of the lack of the Authorization header are handled, not the 401 / 403 in general 🙂

@jeroenheijmans
Copy link
Collaborator

I think so, yeah. AFAIK there's no feature in the library to handle 401/403 when the bearer token is already being sent.

@jeroenheijmans
Copy link
Collaborator

Think the questions in this thread got answered, and since related issues and PRs have been resolved as well I'm going to close this issue.

Let us know if the issue should be re-opened (and what open issue still remains)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants