WWW-Authenticate
header does not match failed authenticator
#9769
Unanswered
orez-rj
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Similar issue has been raised before issue 3800 but I think it should be reconsidered.
DRF’s behavior is technically compliant with RFC 7235, but misleading in practice.
When multiple
authentication_classes
are used, DRF always returns theWWW-Authenticate
header from the first class, even if a later authenticator is the one that rejected the request.While RFC 7235 §4.1 allows a response to include “at least one challenge,” it expects that challenge to be applicable to the request, and in the current DRF behavior, this leads to misleading responses.
Example:
If the client sends
Authorization: Token abc123
(which fails), DRF still returns:This is confusing for clients, misrepresents the actual failure, and makes debugging harder.
The expected behavior is to return the challenge from the authenticator that raised the exception.
This would:
Developers could still choose between "browsers should/should not respond with an authentication dialog" by implementing the
authenticate_header
method.Would you be open to a PR that corrects this?
Beta Was this translation helpful? Give feedback.
All reactions