diff --git a/bioblend/galaxyclient.py b/bioblend/galaxyclient.py index 3a6c168e0..a48665a61 100644 --- a/bioblend/galaxyclient.py +++ b/bioblend/galaxyclient.py @@ -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, @@ -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 self.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.