Skip to content

Commit

Permalink
Make ecoinvent SSO client id configurable
Browse files Browse the repository at this point in the history
* As requested on #34, this sends a different client id to keycloak

#34 (comment)

Signed-off-by: João Gonçalves <[email protected]>
  • Loading branch information
jsvgoncalves committed Oct 18, 2024
1 parent 4a7c107 commit 6e285ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ecoinvent_interface/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions ecoinvent_interface/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6e285ef

Please sign in to comment.