From e227bdfa4c080af8983ea122a1a4555aff37b869 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 3a6c168e0..a8fc54e50 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 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.