WWW-Authenticate header does not match failed authenticator
#9769
Replies: 1 comment
|
Reproduced on DRF 3.18.0. Two authenticators, the second one actively rejecting the credentials: class V(APIView):
authentication_classes = [BearerAuth, TokenishAuth] # TokenishAuth raises AuthenticationFailed
permission_classes = [IsAuthenticated]So the challenge is identical in all three cases, including the one where One detail that shapes any fix: DRF sends a single challenge, from the first authenticator, whereas RFC 7235 §4.1 defines There's also a case where "the authenticator that failed" is ambiguous: when no Worth splitting the two in the proposal, since the multi-challenge version needs no rule for picking a winner. |
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_classesare used, DRF always returns theWWW-Authenticateheader 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_headermethod.Would you be open to a PR that corrects this?
All reactions