Skip to content

Commit

Permalink
Add support for API auth with access token
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwang committed Nov 10, 2023
1 parent 933b910 commit e227bdf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bioblend/galaxyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
self,
url: str,
key: Optional[str] = None,
token: Optional[str] = None,
email: Optional[str] = None,
password: Optional[str] = None,
verify: bool = True,
Expand Down Expand Up @@ -72,13 +73,18 @@ def __init__(
# password and grab user's key before first request.
if key:
self._key: Optional[str] = key
elif token:
self.token: Optional[str] = token
else:
self._key = None
self.email = email
self.password = password
self.json_headers: dict = {"Content-Type": "application/json"}
# json_headers needs to be set before key can be defined, otherwise authentication with email/password causes an error
self.json_headers["x-api-key"] = self.key
if token:
self.json_headers["Authorization"] = f"Bearer {self.token}"
else:
self.json_headers["x-api-key"] = self.key
# Number of attempts before giving up on a GET request.
self._max_get_attempts = 1
# Delay in seconds between subsequent retries.
Expand Down

0 comments on commit e227bdf

Please sign in to comment.