Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Dec 10, 2024
1 parent e7b5aeb commit 93ce6a4
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions custom_components/polestar_api/pypolestar/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,47 @@ async def get_token(self, refresh=False) -> None:
or self.token_expiry < datetime.now(tz=timezone.utc)
):
if (code := await self._get_code()) is None:
self.logger.error("No code")
return

data = {
token_request = {
"grant_type": "authorization_code",
"client_id": OIDC_CLIENT_ID,
"code": code,
"code_verifier": self.code_verifier,
"redirect_uri": OIDC_REDIRECT_URI,
"client_id": OIDC_CLIENT_ID,
**(
{
"code_verifier": self.code_verifier,
}
if self.code_verifier
else {}
),
}

elif self.refresh_token:
data = {
token_request = {
"grant_type": "refresh_token",
"code_verifier": self.code_verifier,
"redirect_uri": OIDC_REDIRECT_URI,
"refresh_token": self.refresh_token,
"client_id": OIDC_CLIENT_ID,
"refresh_token": self.refresh_token,
"redirect_uri": OIDC_REDIRECT_URI,
**(
{
"code_verifier": self.code_verifier,
}
if self.code_verifier
else {}
),
}
else:
return

self.logger.debug("Call token endpoint with grant_type=%s", data["grant_type"])
self.logger.debug(
"Call token endpoint with grant_type=%s", token_request["grant_type"]
)

try:
result = await self.client_session.post(
self.oidc_configuration["token_endpoint"],
data=data,
data=token_request,
timeout=HTTPX_TIMEOUT,
)
except Exception as exc:
Expand All @@ -142,6 +155,7 @@ async def _get_code(self) -> None:

# get the resume path
if not (resume_path := query_params.get("resumePath")):
self.logger.warning("Missing resumePath in authorization response")
return

params = {"client_id": OIDC_CLIENT_ID}
Expand Down

0 comments on commit 93ce6a4

Please sign in to comment.