validate_api_key: Accept the request as an argument.

This is a prerequisite for checking the subdomain of the request.
This commit is contained in:
Tim Abbott
2016-09-27 21:13:43 -07:00
parent bbab3cdc30
commit 15f6cc7c84
2 changed files with 12 additions and 12 deletions

View File

@@ -160,8 +160,8 @@ def process_client(request, user_profile, is_json_view=False, client_name=None):
request.client = get_client(client_name)
update_user_activity(request, user_profile)
def validate_api_key(role, api_key, is_webhook=False):
# type: (text_type, text_type, bool) -> Union[UserProfile, Deployment]
def validate_api_key(request, role, api_key, is_webhook=False):
# type: (HttpRequest, text_type, text_type, bool) -> Union[UserProfile, Deployment]
# Remove whitespace to protect users from trivial errors.
role, api_key = role.strip(), api_key.strip()
@@ -330,7 +330,7 @@ def authenticated_api_view(is_webhook=False):
raise RequestVariableMissingError("api_key")
elif not api_key:
api_key = api_key_legacy
user_profile = validate_api_key(email, api_key, is_webhook)
user_profile = validate_api_key(request, email, api_key, is_webhook)
request.user = user_profile
request._email = user_profile.email
process_client(request, user_profile)
@@ -367,7 +367,7 @@ def authenticated_rest_api_view(is_webhook=False):
# Now we try to do authentication or die
try:
# Could be a UserProfile or a Deployment
profile = validate_api_key(role, api_key, is_webhook)
profile = validate_api_key(request, role, api_key, is_webhook)
except JsonableError as e:
return json_unauthorized(e.error)
request.user = profile