From e9c3944c117299ddff0d81b9f0df8aed642df6c8 Mon Sep 17 00:00:00 2001 From: nuwang <2070605+nuwang@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:55:12 +0530 Subject: [PATCH] Add support for API auth with access token --- bioblend/galaxyclient.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bioblend/galaxyclient.py b/bioblend/galaxyclient.py index c33c4c831..7c0d8f1ca 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, *, @@ -73,13 +74,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.