Skip to content

Commit 9a7f727

Browse files
committed
Add Connection.authenticate_bearer_token
related to #719/#723
1 parent 29a3276 commit 9a7f727

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

openeo/rest/connection.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ def authenticate_oidc_authorization_code(
359359
360360
.. deprecated:: 0.19.0
361361
Usage of the Authorization Code flow is deprecated (because of its complexity) and will be removed.
362-
It is recommended to use the Device Code flow with :py:meth:`authenticate_oidc_device`
363-
or Client Credentials flow with :py:meth:`authenticate_oidc_client_credentials`.
362+
It is recommended to use the Device Code flow with :py:meth:`Connection.authenticate_oidc_device`
363+
or Client Credentials flow with :py:meth:`Connection.authenticate_oidc_client_credentials`.
364364
"""
365365
provider_id, client_info = self._get_oidc_provider_and_client_info(
366366
provider_id=provider_id, client_id=client_id, client_secret=client_secret,
@@ -612,8 +612,6 @@ def authenticate_oidc_access_token(self, access_token: str, provider_id: Optiona
612612
:param access_token: OIDC access token
613613
:param provider_id: id of the OIDC provider as listed by the openEO backend (``/credentials/oidc``).
614614
If not specified, the first (default) OIDC provider will be used.
615-
:param skip_verification: Skip clients-side verification of the provider_id
616-
against the backend's list of providers to avoid and related OIDC configuration
617615
618616
.. versionadded:: 0.31.0
619617
@@ -625,6 +623,23 @@ def authenticate_oidc_access_token(self, access_token: str, provider_id: Optiona
625623
self._oidc_auth_renewer = None
626624
return self
627625

626+
def authenticate_bearer_token(self, bearer_token: str) -> Connection:
627+
"""
628+
Set up authorization headers directly with a bearer token.
629+
630+
.. warning::
631+
This helper is for advanced usage only.
632+
In general, it is recommended to use the more standard OIDC authentication methods
633+
like :py:meth:`Connection.authenticate_oidc`.
634+
635+
:param bearer_token: openEO-style bearer token.
636+
637+
.. versionadded:: 0.38.0
638+
"""
639+
self.auth = BearerAuth(bearer=bearer_token)
640+
self._oidc_auth_renewer = None
641+
return self
642+
628643
def request(
629644
self,
630645
method: str,

tests/rest/test_connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,12 @@ def test_authenticate_oidc_access_token_wrong_provider(self):
25122512
):
25132513
connection.authenticate_oidc_access_token(access_token="Th3Tok3n!@#", provider_id="nope")
25142514

2515+
def test_authenticate_bearer_token(self):
2516+
connection = Connection(API_URL)
2517+
connection.authenticate_bearer_token("custom/foo/b666r")
2518+
assert isinstance(connection.auth, BearerAuth)
2519+
assert connection.auth.bearer == "custom/foo/b666r"
2520+
25152521

25162522
class TestLoadCollection:
25172523
def test_load_collection_arguments_basic(self, dummy_backend):

0 commit comments

Comments
 (0)