From e04a676419be87c7d9ac1967a6b637904fa729e4 Mon Sep 17 00:00:00 2001 From: Keith Bauer Date: Mon, 29 Jul 2024 10:00:48 -0500 Subject: [PATCH] Authorization header fixes --- api/authenticator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/authenticator.py b/api/authenticator.py index 9e88280a8..4304c6729 100644 --- a/api/authenticator.py +++ b/api/authenticator.py @@ -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: @@ -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 ) ): @@ -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)