Skip to content

Commit 6120b39

Browse files
Fix token authentication bugs (#27)
Co-authored-by: Stephen Finucane <[email protected]>
1 parent 88adfe2 commit 6120b39

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pwclient/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ def _generate_headers(self, additional_headers=None):
457457
}
458458

459459
if self._token:
460-
pass
461-
462-
if self._username:
460+
headers['Authorization'] = f"Token {self._token}"
461+
elif self._username and self._password:
463462
credentials = base64.b64encode(
464463
f'{self._username}:{self._password}'.encode('ascii')
465464
).decode('ascii')

pwclient/shell.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ def main(argv=sys.argv[1:]):
9292
if action in auth_actions:
9393
if backend == 'rest':
9494
if not (
95-
config.has_option(project_str, 'username')
96-
and config.has_option(project_str, 'password')
97-
) or config.has_option(project_str, 'token'):
95+
(
96+
config.has_option(project_str, 'username')
97+
and config.has_option(project_str, 'password')
98+
)
99+
or config.has_option(project_str, 'token')
100+
):
98101
sys.stderr.write(
99102
"The %s action requires authentication, but no "
100103
"username/password or\n"

0 commit comments

Comments
 (0)