Skip to content

Commit

Permalink
Connection.authenticate_oidc: allow to specify the display callable
Browse files Browse the repository at this point in the history
for displaying authentication instructions
  • Loading branch information
soxofaan committed Mar 28, 2023
1 parent 86621b6 commit 509b4a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions openeo/rest/auth/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,9 @@ def __init__(
self,
client_info: OidcClientInfo,
display: Callable[[str], None] = print,
device_code_url: str = None,
max_poll_time=5 * 60,
use_pkce: Union[bool, None] = None,
device_code_url: Optional[str] = None,
max_poll_time: float = 5 * 60,
use_pkce: Optional[bool] = None,
requests_session: Optional[requests.Session] = None,
):
super().__init__(client_info=client_info, requests_session=requests_session)
Expand Down
22 changes: 15 additions & 7 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,13 @@ def authenticate_oidc_device(
return self._authenticate_oidc(authenticator, provider_id=provider_id, store_refresh_token=store_refresh_token)

def authenticate_oidc(
self,
provider_id: str = None,
client_id: Union[str, None] = None, client_secret: Union[str, None] = None,
store_refresh_token: bool = True,
use_pkce: Union[bool, None] = None,
self,
provider_id: Optional[str] = None,
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
store_refresh_token: bool = True,
use_pkce: Optional[bool] = None,
display: Callable[[str], None] = print,
):
"""
Do OpenID Connect authentication, first trying refresh tokens and falling back on device code flow.
Expand Down Expand Up @@ -575,8 +577,14 @@ def authenticate_oidc(
# Fall back on device code flow
# TODO: make it possible to do other fallback flows too?
_log.info("Trying device code flow.")
authenticator = OidcDeviceAuthenticator(client_info=client_info, use_pkce=use_pkce)
con = self._authenticate_oidc(authenticator, provider_id=provider_id, store_refresh_token=store_refresh_token)
authenticator = OidcDeviceAuthenticator(
client_info=client_info, use_pkce=use_pkce, display=display
)
con = self._authenticate_oidc(
authenticator,
provider_id=provider_id,
store_refresh_token=store_refresh_token,
)
print("Authenticated using device code flow.")
return con

Expand Down

0 comments on commit 509b4a4

Please sign in to comment.