-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add support for multiple authentication challenges in WWW-Authenticate header #9242
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
1cd663c
0a53bb0
8c23de2
525979e
ea612e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from django.core.checks import Tags, Warning, register | ||
from django.core.checks import Tags, Error, Warning, register | ||
|
||
|
||
@register(Tags.compatibility) | ||
|
@@ -19,3 +19,22 @@ def pagination_system_check(app_configs, **kwargs): | |
) | ||
) | ||
return errors | ||
|
||
|
||
@register(Tags.compatibility) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably should be Those checks also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with I'm happy to go with any of these options, just let me know what you prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I have no strong preference. |
||
def www_authenticate_behavior_setting_check(app_configs, **kwargs): | ||
errors = [] | ||
# WWW_AUTHENTICATE_BEHAVIOR setting must be 'first' or 'all' | ||
from rest_framework.settings import api_settings | ||
setting = api_settings.WWW_AUTHENTICATE_BEHAVIOR | ||
if setting not in ['first', 'all']: | ||
errors.append( | ||
Error( | ||
"The rest_framework setting WWW_AUTHENTICATE_BEHAVIOR must be either " | ||
f"'first' or 'all' (it is currently set to '{setting}').", | ||
hint="Set WWW_AUTHENTICATE_BEHAVIOR to either 'first' or 'all', " | ||
"or leave it unset (the default value is 'first').", | ||
id="rest_framework.E001", | ||
) | ||
) | ||
return errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary? In my local build I was able to trigger the new error without it; I merely copied the pattern from the line above in my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question; have you been able to understand this further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is following this advice from the Django docs:
When you say you were able to trigger the new error without this: did this happen on startup, or when you ran
check
manually?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand this better now.
The
@register
decorator causes the check function to be registered; all that's required beyond using the decorator is to arrange to load the module in which those functions live. That's why omitting this line still allows my check to be performed (on both startup, and when invoking thecheck
management command manually, as it happens): the previous line causes the whole module to load, which causes not justpagination_system_check
but my new check function to be registered as well.I tested this theory by removing both lines; in that case, my check does not run. But this means that both lines can be replaced with just
from . import checks
; that's sufficient to register all the check functions in that module.I hope all this made sense 🙂. If it does, I'll plan to make that change and resolve this conversation.