Skip to content

Commit 6e07c8c

Browse files
authored
Accommodate SimpliSafe API changes (#488)
* Accommodate SimpliSafe API changes * Fix type annotations
1 parent 0e2e1b7 commit 6e07c8c

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

simplipy/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def _save_token_data_from_response(self, token_data: dict[str, Any]) -> None:
255255
"""
256256
self._token_last_refreshed = datetime.utcnow()
257257
self.access_token = token_data["access_token"]
258-
self.refresh_token = token_data["refresh_token"]
258+
if refresh_token := token_data.get("refresh_token"):
259+
self.refresh_token = refresh_token
259260

260261
@staticmethod
261262
def is_fatal_error(err: ClientResponseError) -> bool:

simplipy/util/auth.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
"""Define some utilities to work with SimpliSafe's authentication mechanism."""
2+
from __future__ import annotations
3+
24
import base64
35
import hashlib
46
import os
57
import re
68
import urllib.parse
9+
from uuid import uuid4
710

811
AUTH_URL_HOSTNAME = "auth.simplisafe.com"
912
AUTH_URL_BASE = f"https://{AUTH_URL_HOSTNAME}"
1013
AUTH_URL_LOGIN = f"{AUTH_URL_BASE}/authorize"
1114

1215
DEFAULT_AUTH0_CLIENT = (
13-
"eyJuYW1lIjoiQXV0aDAuc3dpZnQiLCJlbnYiOnsiaU"
14-
"9TIjoiMTUuMCIsInN3aWZ0IjoiNS54In0sInZlcnNpb24iOiIxLjMzLjAifQ"
16+
"eyJ2ZXJzaW9uIjoiMi4zLjIiLCJuYW1lIjoiQXV0aDAuc3dpZnQiLCJlbnYiOnsic3dpZnQiOiI1LngiLC"
17+
"JpT1MiOiIxNi4zIn19"
1518
)
1619
DEFAULT_CLIENT_ID = "42aBZ5lYrVW12jfOuu3CQROitwxg9sN5"
1720
DEFAULT_REDIRECT_URI = (
@@ -22,12 +25,14 @@
2225
)
2326

2427

25-
def get_auth_url(code_challenge: str) -> str:
28+
def get_auth_url(code_challenge: str, *, device_id: str | None = None) -> str:
2629
"""Get a SimpliSafe authorization URL to visit in a browser.
2730
2831
Args:
2932
code_challenge: A code challenge generated by
3033
:meth:`simplipy.util.auth.get_auth0_code_challenge`.
34+
device_id: A UUID to identify the device getting the auth URL. If not
35+
provided, a random UUID will be generated.
3136
3237
Returns:
3338
An authorization URL.
@@ -38,6 +43,8 @@ def get_auth_url(code_challenge: str) -> str:
3843
"client_id": DEFAULT_CLIENT_ID,
3944
"code_challenge": code_challenge,
4045
"code_challenge_method": "S256",
46+
"device": "iPhone",
47+
"device_id": (device_id or str(uuid4())).upper(),
4148
"redirect_uri": DEFAULT_REDIRECT_URI,
4249
"response_type": "code",
4350
"scope": DEFAULT_SCOPE,

0 commit comments

Comments
 (0)