From 6120b3995e6bb95bde20538db5573b5d8ca0b718 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Fri, 17 Nov 2023 12:35:20 +0000 Subject: [PATCH] Fix token authentication bugs (#27) Co-authored-by: Stephen Finucane --- pwclient/api.py | 5 ++--- pwclient/shell.py | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pwclient/api.py b/pwclient/api.py index fcd3673..427395b 100644 --- a/pwclient/api.py +++ b/pwclient/api.py @@ -457,9 +457,8 @@ def _generate_headers(self, additional_headers=None): } if self._token: - pass - - if self._username: + headers['Authorization'] = f"Token {self._token}" + elif self._username and self._password: credentials = base64.b64encode( f'{self._username}:{self._password}'.encode('ascii') ).decode('ascii') diff --git a/pwclient/shell.py b/pwclient/shell.py index 4f3fb40..304e61c 100644 --- a/pwclient/shell.py +++ b/pwclient/shell.py @@ -92,9 +92,12 @@ def main(argv=sys.argv[1:]): if action in auth_actions: if backend == 'rest': if not ( - config.has_option(project_str, 'username') - and config.has_option(project_str, 'password') - ) or config.has_option(project_str, 'token'): + ( + config.has_option(project_str, 'username') + and config.has_option(project_str, 'password') + ) + or config.has_option(project_str, 'token') + ): sys.stderr.write( "The %s action requires authentication, but no " "username/password or\n"