Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use injected keycloak token from onyxia in toolbelt auth client #179

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 49 additions & 35 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 33 additions & 7 deletions src/dapla/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,19 @@ def fetch_google_credentials(force_token_exchange: bool = False) -> Credentials:

@staticmethod
def fetch_personal_token() -> str:
"""Fetches the personal access token for the current user."""
try:
personal_token = AuthClient.fetch_local_user_from_jupyter()["access_token"]
return t.cast(str, personal_token)
except AuthError as err:
err._print_warning()
raise err
"""Retrieve the OIDC token/Keycloak token from the environment.

Returns:
str: The OIDC token.

Raises:
MissingConfigurationException: If the OIDC_TOKEN environment variable is not set.
"""
keycloak_token = os.getenv("OIDC_TOKEN")
if not keycloak_token:
raise MissingConfigurationException("OIDC_TOKEN")
else:
return keycloak_token

@staticmethod
@lru_cache(maxsize=1)
Expand Down Expand Up @@ -336,3 +342,23 @@ def _print_warning(self) -> None:
)
)
)


class MissingConfigurationException(Exception):
"""Exception raised when a required environment variable or configuration is missing."""

def __init__(self, variable_name: str) -> None:
"""Initializes a new instance of the MissingConfigurationException class.

Args:
variable_name (str): The name of the missing environment variable or configuration.
message (str): The error message to be displayed. Defaults to an empty string.

"""
self.variable_name = variable_name
self.message = f"Missing required environment variable: {variable_name}"
super().__init__(self.message)

def __str__(self) -> str:
"""Returns a string representation of the exception."""
return f"Configuration error: {self.message}"
Loading
Loading