Skip to content

Commit

Permalink
Merge pull request #1934 from NYPL-Simplified/develop
Browse files Browse the repository at this point in the history
Authorization header fixes
  • Loading branch information
keithbauer authored Jul 29, 2024
2 parents 440c302 + e04a676 commit dde7385
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ def authenticated_patron(self, _db, header):
# Set provider_name and provider_token so it can be referenced
# in the basic auth provider check.
provider_name, provider_token = None, None
if isinstance(header, auth.Authorization):
header = header.parameters or header.to_header()

if isinstance(header, (bytes, str)):
try:
Expand All @@ -834,7 +836,7 @@ def authenticated_patron(self, _db, header):

if (self.basic_auth_provider
and (
(isinstance(header, (dict, auth.Authorization)) and 'username' in header)
(isinstance(header, dict) and 'username' in header)
or provider_name == BasicAuthenticationProvider.BEARER_TOKEN_PROVIDER_NAME
)
):
Expand Down Expand Up @@ -2108,7 +2110,9 @@ def get_credential_from_header(self, header):
:param header: A dictionary with keys `username` and `password`.
"""
if not isinstance(header, (dict, auth.Authorization)):
if isinstance(header, auth.Authorization):
header = header.parameters
elif not isinstance(header, dict):
return None
return header.get('password', None)

Expand Down

0 comments on commit dde7385

Please sign in to comment.