diff --git a/lowatt_grdf/api.py b/lowatt_grdf/api.py index b7b7b11..6f3a64f 100644 --- a/lowatt_grdf/api.py +++ b/lowatt_grdf/api.py @@ -28,8 +28,6 @@ from . import LOGGER, models -OPENID_ENDPOINT = "https://sofit-sso-oidc.grdf.fr/openam/oauth2/realms/externeGrdf" - def raise_for_status(resp: requests.Response) -> None: try: @@ -54,6 +52,11 @@ def scope(self) -> str: def api(self) -> str: raise NotImplementedError() + @property + @abc.abstractmethod + def auth_endpoint(self) -> str: + raise NotImplementedError() + def __init__(self, client_id: str, client_secret: str): self.client_id = client_id self.client_secret = client_secret @@ -88,7 +91,7 @@ def access_token(self) -> str: def _authenticate(self) -> tuple[str, float]: resp = requests.post( - f"{OPENID_ENDPOINT}/access_token", + self.auth_endpoint, data={ "grant_type": "client_credentials", "client_id": self.client_id, @@ -214,8 +217,14 @@ def donnees_techniques(self, pce: str) -> Any: class StagingAPI(BaseAPI): scope = "/adict/bas/v4" api = "https://api.grdf.fr/adict/bas/v4" + auth_endpoint = ( + "https://sofit-sso-oidc.grdf.fr/openam/oauth2/realms/externeGrdf/access_token" + ) class API(BaseAPI): scope = "/adict/v2" api = "https://api.grdf.fr/adict/v2" + auth_endpoint = ( + "https://adict-connexion.grdf.fr/oauth2/aus5y2ta2uEHjCWIR417/v1/token" + )