Skip to content

Commit

Permalink
fall back to single auth/token url since they're not interchangable
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-oracle committed Feb 14, 2025
1 parent a8b58cc commit 30e7d10
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 74 deletions.
57 changes: 20 additions & 37 deletions py_uconnect/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,13 @@ def login(self):
if r["statusCode"] != 200:
raise Exception(f"unable to obtain JWT: {r}")

exc = None
for url in self.brand.token_url:
try:
r = self.sess.request(
method="POST",
url=url,
headers=self._default_aws_headers(self.brand.api.key)
| {"content-type": "application/json"},
json={"gigya_token": r["id_token"]},
)
except Exception as e:
exc = e
else:
break
else:
raise Exception(f"unable to obtain token: {exc}")
r = self.sess.request(
method="POST",
url=self.brand.token_url,
headers=self._default_aws_headers(self.brand.api.key)
| {"content-type": "application/json"},
json={"gigya_token": r["id_token"]},
)

r.raise_for_status()
_LOGGER.debug(f"Login: obtain token: {r.text}")
Expand Down Expand Up @@ -340,27 +331,19 @@ def command(self, vin: str, cmd: Command):

self._refresh_token_if_needed()

exc = None
for auth in self.brand.auth:
try:
r = self.sess.request(
method="POST",
url=auth.url + f"/v1/accounts/{self.uid}/ignite/pin/authenticate",
headers=self._default_aws_headers(auth.token)
| {"content-type": "application/json"},
auth=self.aws_auth,
json=data,
)

r.raise_for_status()
_LOGGER.debug(f"command auth ({vin} {cmd}): {r.text}")
r = r.json()
except Exception as e:
exc = e
else:
break
else:
raise Exception(f"Authentication failed: {exc}")
r = self.sess.request(
method="POST",
url=self.brand.auth.url
+ f"/v1/accounts/{self.uid}/ignite/pin/authenticate",
headers=self._default_aws_headers(self.brand.auth.token)
| {"content-type": "application/json"},
auth=self.aws_auth,
json=data,
)

r.raise_for_status()
_LOGGER.debug(f"command auth ({vin} {cmd}): {r.text}")
r = r.json()

if not "token" in r:
raise Exception(f"authentication failed: no token found: {r}")
Expand Down
72 changes: 36 additions & 36 deletions py_uconnect/brands.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class Brand:
region: str
login_api_key: str
login_url: str
token_url: list[str]
token_url: str
api: API
auth: list[Auth]
auth: Auth
locale: str

def __repr__(self):
Expand All @@ -73,9 +73,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="3_mOx_J2dRgjXYCdyhchv3b5lhi54eBcdCTX4BI8MORqmZCoQWhA0mV2PTlptLGUQI",
login_url="https://loginmyuconnect.fiat.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -84,9 +84,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_WfFvlZJwcSdOD0LFQCngUV3W390R4Yshpuq3RsZvnV4VG0c9Q6R0RtDwcXc8dTrI",
login_url="https://login-us.fiat.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_US,
)

Expand All @@ -95,9 +95,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="4_YAQNaPqdPEUbbzhvhunKAA",
login_url="https://login-iap.fiat.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -106,9 +106,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_Ii2kSgQm4ljy19LIZeLwa76OlmWbpSa8w3aSP5VJdx19tub3oWxsFR-HEusDnUEh",
login_url="https://login-stage-us.fiat.com",
token_url={TOKEN_URL_US_PREP, TOKEN_URL_US, TOKEN_URL_EU},
token_url=TOKEN_URL_US_PREP,
api=API_US,
auth=[AUTH_US_PREP, AUTH_US, AUTH_EU],
auth=AUTH_US_PREP,
locale=LOCALE_US,
)

Expand All @@ -117,9 +117,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_FSxGyaktviayTDRcgp9r9o2KjuFSrHT13wWNN9zPrvAGUCoXPDqoIPOwlBUhck4A",
login_url="https://login-us.alfaromeo.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand All @@ -128,9 +128,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="4_PSQeADnQ4p5XOaDgT0B5pA",
login_url="https://login-iap.alfaromeo.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -139,9 +139,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="3_h8sj2VQI-KYXiunPq9a1QuAA4yWkY0r5AD1u8A8B1RPn_Cvl54xcoc2-InH5onJ1",
login_url="https://login.alfaromeo.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -150,9 +150,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_gdhu-ur4jc2hEryDMnF4YPELkjzSi-invZTjop4isZu4ReHodVcuL44u93cOUqMC",
login_url="https://login-stage-us.chrysler.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand All @@ -161,9 +161,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_cv4AzHkJh48-cqwaf_Ahcg1HnsmQqz1lm0sOdVdHW5FjT3m6SyywywOBaskBQqwn",
login_url="https://login-us.chrysler.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand All @@ -172,9 +172,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="3_rNbVuhn2gIt3BnLjlGsJcMo26Lft3avDne_FLRT34Dy_9OxHtCVOnplwY436lGZa",
login_url="https://login.maserati.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -183,9 +183,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="4_uwF-in6KF-aMbEkPAb-fOg",
login_url="https://accounts.au1.gigya.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -194,9 +194,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_nShL4-O7IL0OGqroO8AzwiRU0-ZHcBZ4TLBrh5MORusMo5XYxhCLXPYfjI4OOLOy",
login_url="https://login-us.maserati.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand All @@ -205,9 +205,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="3_ZvJpoiZQ4jT5ACwouBG5D1seGEntHGhlL0JYlZNtj95yERzqpH4fFyIewVMmmK7j",
login_url="https://login.jeep.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -216,9 +216,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_5qxvrevRPG7--nEXe6huWdVvF5kV7bmmJcyLdaTJ8A45XUYpaR398QNeHkd7EB1X",
login_url="https://login-us.jeep.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand All @@ -227,9 +227,9 @@ def __repr__(self):
region=REGION_EU,
login_api_key="4_zqGYHC7rM8RCHHl4YFDebA",
login_url="https://login-iap.jeep.com",
token_url=[TOKEN_URL_EU, TOKEN_URL_US],
token_url=TOKEN_URL_EU,
api=API_EU,
auth=[AUTH_EU, AUTH_US],
auth=AUTH_EU,
locale=LOCALE_EU,
)

Expand All @@ -238,9 +238,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="4_dSRvo6ZIpp8_St7BF9VHGA",
login_url="https://login-us.dodge.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand All @@ -249,9 +249,9 @@ def __repr__(self):
region=REGION_US,
login_api_key="3_7YjzjoSb7dYtCP5-D6FhPsCciggJFvM14hNPvXN9OsIiV1ujDqa4fNltDJYnHawO",
login_url="https://login-us.ramtrucks.com",
token_url=[TOKEN_URL_US, TOKEN_URL_EU],
token_url=TOKEN_URL_US,
api=API_US,
auth=[AUTH_US, AUTH_EU],
auth=AUTH_US,
locale=LOCALE_US,
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
name="py-uconnect",
packages=find_packages(include=["py_uconnect", "py_uconnect.*"]),
url="https://github.com/hass-uconnect/py-uconnect",
version="0.2.5",
version="0.2.6",
zip_safe=False,
)

0 comments on commit 30e7d10

Please sign in to comment.