-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Support API key as password for excel feeds #35698
base: master
Are you sure you want to change the base?
Changes from 4 commits
e2b5a68
3aeb474
9ef3d0b
c69e1f2
b1e0607
4cda82c
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -364,7 +364,9 @@ def login_or_oauth2_ex(allow_cc_users=False, allow_sessions=True, require_domain | |||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
def get_multi_auth_decorator(default, allow_formplayer=False, oauth_scopes=None, allow_creds_in_data=True): | ||||||||||
def get_multi_auth_decorator( | ||||||||||
default, allow_formplayer=False, oauth_scopes=None, allow_creds_in_data=True, allow_api_key_as_password=False | ||||||||||
): | ||||||||||
""" | ||||||||||
:param allow_formplayer: If True this will allow one additional auth mechanism which is used | ||||||||||
by Formplayer: | ||||||||||
|
@@ -373,6 +375,7 @@ def get_multi_auth_decorator(default, allow_formplayer=False, oauth_scopes=None, | |||||||||
formplayer can not use the session cookie to auth. To allow formplayer access to the | ||||||||||
endpoints we validate each formplayer request using a shared key. See the auth | ||||||||||
function for more details. | ||||||||||
:param allow_api_key_as_password: If True, allows API Key to be used in BASIC auth | ||||||||||
""" | ||||||||||
oauth_scopes = oauth_scopes or ['access_apis'] | ||||||||||
|
||||||||||
|
@@ -391,6 +394,7 @@ def _inner(request, *args, **kwargs): | |||||||||
allow_cc_users=True, | ||||||||||
oauth_scopes=oauth_scopes, | ||||||||||
allow_creds_in_data=allow_creds_in_data, | ||||||||||
allow_api_key_as_password=allow_api_key_as_password, | ||||||||||
)[authtype] | ||||||||||
return function_wrapper(fn)(request, *args, **kwargs) | ||||||||||
return _inner | ||||||||||
|
@@ -410,12 +414,13 @@ def wrapped_view(*args, **kwargs): | |||||||||
return wraps(view_func)(wrapped_view) | ||||||||||
|
||||||||||
|
||||||||||
def api_auth(*, allow_creds_in_data=True, oauth_scopes=None): | ||||||||||
def api_auth(*, allow_creds_in_data=True, oauth_scopes=None, allow_api_key_as_password=False): | ||||||||||
"""Allow any auth type basic, digest, session, apikey, or oauth""" | ||||||||||
return get_multi_auth_decorator( | ||||||||||
default=DIGEST, | ||||||||||
oauth_scopes=oauth_scopes, | ||||||||||
allow_creds_in_data=allow_creds_in_data, | ||||||||||
allow_api_key_as_password=allow_api_key_as_password, | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
|
@@ -435,6 +440,7 @@ def get_auth_decorator_map( | |||||||||
allow_sessions=True, | ||||||||||
oauth_scopes=None, | ||||||||||
allow_creds_in_data=True, | ||||||||||
allow_api_key_as_password=False, | ||||||||||
): | ||||||||||
# get a mapped set of decorators for different auth types with the specified parameters | ||||||||||
oauth_scopes = oauth_scopes or ['access_apis'] | ||||||||||
|
@@ -443,9 +449,17 @@ def get_auth_decorator_map( | |||||||||
'require_domain': require_domain, | ||||||||||
'allow_sessions': allow_sessions, | ||||||||||
} | ||||||||||
|
||||||||||
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. re:
Would it make sense to assert that here?
Suggested change
I assume it's not easy or very meaningful to add tests to verify that our code never does that, but if it's possible to verify with a test then that might make sense too. |
||||||||||
if allow_api_key_as_password: | ||||||||||
copied_kwargs = decorator_function_kwargs.copy() | ||||||||||
copied_kwargs.pop('require_domain') | ||||||||||
basic_auth_fn = login_or_basic_or_api_key_ex(**copied_kwargs) | ||||||||||
else: | ||||||||||
basic_auth_fn = login_or_basic_ex(**decorator_function_kwargs) | ||||||||||
gherceg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
return { | ||||||||||
DIGEST: login_or_digest_ex(**decorator_function_kwargs), | ||||||||||
BASIC: login_or_basic_ex(**decorator_function_kwargs), | ||||||||||
BASIC: basic_auth_fn, | ||||||||||
API_KEY: login_or_api_key_ex(allow_creds_in_data=allow_creds_in_data, | ||||||||||
**decorator_function_kwargs), | ||||||||||
OAUTH2: login_or_oauth2_ex(oauth_scopes=oauth_scopes, **decorator_function_kwargs), | ||||||||||
|
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 the thing that you were referring to with this comment?
If yes, maybe add that concern to this docstring to warn future devs not to use it in exceptional circumstances? Possibly even rename the parameter to something like
allow_api_key_as_password_EXCEPTIONAL_USE_ONLY
to force anyone who uses it to type that out and as a flag to reviewers?