Skip to content

Commit 588aef0

Browse files
committed
Update api.py
Adding urn extraction
1 parent a8c57bd commit 588aef0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pyhilo/api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ async def async_get_access_token(self) -> str:
145145
access_token = str(self._oauth_session.token["access_token"])
146146
LOG.debug("Websocket access token is %s", access_token)
147147

148+
urn = self.urn
149+
LOG.debug("Extracted URN: %s", urn)
150+
148151
return str(self._oauth_session.token["access_token"])
149152

150153
@property
@@ -162,7 +165,12 @@ def urn(self) -> str | None:
162165

163166
decoded = base64.urlsafe_b64decode(payload_part)
164167
claims = json.loads(decoded)
165-
self._urn = claims.get("urn")
168+
urn_claim = claims.get("urn:com:hiloenergie:profile:location_hilo_id")
169+
if urn_claim and isinstance(urn_claim, list) and len(urn_claim) > 0:
170+
self._urn = urn_claim[0] # Get the first URN from the array
171+
else:
172+
self._urn = None
173+
166174
return self._urn
167175
except (IndexError, json.JSONDecodeError, KeyError):
168176
LOG.error("Failed to extract URN from access token")

0 commit comments

Comments
 (0)