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 1/2] 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. From 09b340f9236d09bb46ebcb62be9bd0660ce658e8 Mon Sep 17 00:00:00 2001 From: nuwang <2070605+nuwang@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:09:14 +0530 Subject: [PATCH 2/2] Address review comments --- bioblend/galaxy/__init__.py | 9 ++++++++- bioblend/galaxy/objects/galaxy_instance.py | 5 ++++- bioblend/galaxyclient.py | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bioblend/galaxy/__init__.py b/bioblend/galaxy/__init__.py index 2985bcd32..a9c282155 100644 --- a/bioblend/galaxy/__init__.py +++ b/bioblend/galaxy/__init__.py @@ -39,6 +39,7 @@ def __init__( email: Optional[str] = None, password: Optional[str] = None, *, + token: Optional[str] = None, verify: bool = True, ) -> None: """ @@ -79,10 +80,16 @@ def __init__( :param password: Password of Galaxy account corresponding to the above e-mail address. Ignored if key is supplied directly. + :type token: str + :param token: An OIDC access token obtained from an OIDC provider + configured in `oidc_backends_config.xml`. Can be used + as a substitue for an API key. You must make sure the access + token has not expired when making an API call. + :param verify: Whether to verify the server's TLS certificate :type verify: bool """ - super().__init__(url, key=key, email=email, password=password, verify=verify) + super().__init__(url, key=key, email=email, password=password, token=token, verify=verify) self.libraries = libraries.LibraryClient(self) self.histories = histories.HistoryClient(self) self.workflows = workflows.WorkflowClient(self) diff --git a/bioblend/galaxy/objects/galaxy_instance.py b/bioblend/galaxy/objects/galaxy_instance.py index d4baa81d3..4b2577e6e 100644 --- a/bioblend/galaxy/objects/galaxy_instance.py +++ b/bioblend/galaxy/objects/galaxy_instance.py @@ -57,9 +57,12 @@ def __init__( email: Optional[str] = None, password: Optional[str] = None, *, + token: Optional[str] = None, verify: bool = True, ) -> None: - self.gi = bioblend.galaxy.GalaxyInstance(url, key=api_key, email=email, password=password, verify=verify) + self.gi = bioblend.galaxy.GalaxyInstance( + url, key=api_key, email=email, password=password, token=token, verify=verify + ) self.log = bioblend.log self.datasets = client.ObjDatasetClient(self) self.dataset_collections = client.ObjDatasetCollectionClient(self) diff --git a/bioblend/galaxyclient.py b/bioblend/galaxyclient.py index 7c0d8f1ca..a4b110c42 100644 --- a/bioblend/galaxyclient.py +++ b/bioblend/galaxyclient.py @@ -34,10 +34,10 @@ def __init__( self, url: str, key: Optional[str] = None, - token: Optional[str] = None, email: Optional[str] = None, password: Optional[str] = None, *, + token: Optional[str] = None, verify: bool = True, timeout: Optional[float] = None, ) -> None: