From 6e285ef8c104198bf3e78b70219922a239097caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Gon=C3=A7alves?= Date: Fri, 18 Oct 2024 17:33:45 +0200 Subject: [PATCH] Make ecoinvent SSO client id configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * As requested on #34, this sends a different client id to keycloak https://github.com/brightway-lca/ecoinvent_interface/issues/34#issuecomment-2401534405 Signed-off-by: João Gonçalves --- ecoinvent_interface/core.py | 17 +++++++++++------ ecoinvent_interface/settings.py | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ecoinvent_interface/core.py b/ecoinvent_interface/core.py index 3d993f1..3e31e9e 100644 --- a/ecoinvent_interface/core.py +++ b/ecoinvent_interface/core.py @@ -84,6 +84,7 @@ def __init__( Instance ID: {id(self)} Version: {__version__} User: {self.username} + Client ID: {self.client_id} Output directory: {self.storage.dir} Custom headers: {bool(custom_headers)} Custom URLs: {bool(urls)} @@ -94,31 +95,33 @@ def login(self) -> None: post_data = { "username": self.username, "password": self.password, - "client_id": "apollo-ui", + "client_id": self.client_id, "grant_type": "password", } self._get_credentials(post_data) - message = """Got initial credentials. + message = f"""Got initial credentials. Class: {self.__class__.__name__} Instance ID: {id(self)} Version: {__version__} User: {self.username} + Client ID: {self.client_id} """ logger.debug(message) @logged_in def refresh_tokens(self) -> None: post_data = { - "client_id": "apollo-ui", + "client_id": self.client_id, "grant_type": "refresh_token", "refresh_token": self.refresh_token, } self._get_credentials(post_data) - message = """Renewed credentials. + message = f"""Renewed credentials. Class: {self.__class__.__name__} Instance ID: {id(self)} Version: {__version__} User: {self.username} + Client ID: {self.client_id} """ logger.debug(message) @@ -164,12 +167,13 @@ def _get_all_reports(self) -> dict: "ecoinvent-api-client-library-version": __version__, } headers.update(self.custom_headers) - message = """Requesting URL. + message = f"""Requesting URL. URL: {reports_url} Class: {self.__class__.__name__} Instance ID: {id(self)} Version: {__version__} User: {self.username} + Client ID: {self.client_id} """ logger.debug(message) return requests.get(reports_url, headers=headers, timeout=20).json() @@ -183,12 +187,13 @@ def _get_all_files(self) -> dict: "ecoinvent-api-client-library-version": __version__, } headers.update(self.custom_headers) - message = """Requesting URL. + message = f"""Requesting URL. URL: {files_url} Class: {self.__class__.__name__} Instance ID: {id(self)} Version: {__version__} User: {self.username} + Client ID: {self.client_id} """ logger.debug(message) return requests.get(files_url, headers=headers, timeout=20).json() diff --git a/ecoinvent_interface/settings.py b/ecoinvent_interface/settings.py index 26705ef..d5b6749 100644 --- a/ecoinvent_interface/settings.py +++ b/ecoinvent_interface/settings.py @@ -13,6 +13,7 @@ class Settings(BaseSettings): username: Optional[str] = None password: Optional[str] = None + client_id: str = "brightway-ei" output_path: Optional[str] = None