Skip to content

Commit 0a53bb0

Browse files
committed
Implement alternative WWW-Authenticate generation behaviors
1 parent 1cd663c commit 0a53bb0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

rest_framework/views.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class APIView(View):
107107
renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
108108
parser_classes = api_settings.DEFAULT_PARSER_CLASSES
109109
authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES
110+
www_authenticate_behavior = api_settings.WWW_AUTHENTICATE_BEHAVIOR
110111
throttle_classes = api_settings.DEFAULT_THROTTLE_CLASSES
111112
permission_classes = api_settings.DEFAULT_PERMISSION_CLASSES
112113
content_negotiation_class = api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS
@@ -186,8 +187,13 @@ def get_authenticate_header(self, request):
186187
header to use for 401 responses, if any.
187188
"""
188189
authenticators = self.get_authenticators()
190+
www_authenticate_behavior = self.www_authenticate_behavior
189191
if authenticators:
190-
return authenticators[0].authenticate_header(request)
192+
if www_authenticate_behavior == 'first':
193+
return authenticators[0].authenticate_header(request)
194+
elif www_authenticate_behavior == 'all':
195+
challenges = (a.authenticate_header(request) for a in authenticators)
196+
return ', '.join((c for c in challenges if c is not None))
191197

192198
def get_parser_context(self, http_request):
193199
"""

0 commit comments

Comments
 (0)