Skip to content

Commit 5e651fc

Browse files
authored
Merge pull request #482 from nuwang/add_support_for_access_tokens
Add support for API auth with access token
2 parents 0190929 + 198e326 commit 5e651fc

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

bioblend/galaxy/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(
4040
email: Optional[str] = None,
4141
password: Optional[str] = None,
4242
*,
43+
token: Optional[str] = None,
4344
verify: bool = True,
4445
user_agent: Optional[str] = None,
4546
) -> None:
@@ -81,10 +82,18 @@ def __init__(
8182
:param password: Password of Galaxy account corresponding to the above
8283
e-mail address. Ignored if key is supplied directly.
8384
85+
:type token: str
86+
:param token: An OIDC access token obtained from an OIDC provider
87+
configured in `oidc_backends_config.xml`. Can be used
88+
as a substitue for an API key. You must make sure the access
89+
token has not expired when making an API call.
90+
8491
:param verify: Whether to verify the server's TLS certificate
8592
:type verify: bool
8693
"""
87-
super().__init__(url, key=key, email=email, password=password, verify=verify, user_agent=user_agent)
94+
super().__init__(
95+
url, key=key, email=email, password=password, token=token, verify=verify, user_agent=user_agent
96+
)
8897
self.libraries = libraries.LibraryClient(self)
8998
self.histories = histories.HistoryClient(self)
9099
self.workflows = workflows.WorkflowClient(self)

bioblend/galaxy/objects/galaxy_instance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ def __init__(
5454
email: Optional[str] = None,
5555
password: Optional[str] = None,
5656
*,
57+
token: Optional[str] = None,
5758
verify: bool = True,
5859
user_agent: Optional[str] = None,
5960
) -> None:
6061
self.gi = bioblend.galaxy.GalaxyInstance(
61-
url, key=api_key, email=email, password=password, verify=verify, user_agent=user_agent
62+
url, key=api_key, email=email, password=password, token=token, verify=verify, user_agent=user_agent
6263
)
6364
self.log = bioblend.log
6465
self.datasets = client.ObjDatasetClient(self)

bioblend/galaxyclient.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
email: Optional[str] = None,
4040
password: Optional[str] = None,
4141
*,
42+
token: Optional[str] = None,
4243
verify: bool = True,
4344
timeout: Optional[float] = None,
4445
user_agent: Optional[str] = None,
@@ -76,6 +77,8 @@ def __init__(
7677
# password and grab user's key before first request.
7778
if key:
7879
self._key: Optional[str] = key
80+
elif token:
81+
self.token: Optional[str] = token
7982
else:
8083
self._key = None
8184
self.email = email
@@ -84,7 +87,10 @@ def __init__(
8487
if user_agent:
8588
self.json_headers["User-Agent"] = user_agent
8689
# json_headers needs to be set before key can be defined, otherwise authentication with email/password causes an error
87-
self.json_headers["x-api-key"] = self.key
90+
if token:
91+
self.json_headers["Authorization"] = f"Bearer {token}"
92+
else:
93+
self.json_headers["x-api-key"] = self.key
8894
# Number of attempts before giving up on a GET request.
8995
self._max_get_attempts = 1
9096
# Delay in seconds between subsequent retries.

0 commit comments

Comments
 (0)