11"""Define some utilities to work with SimpliSafe's authentication mechanism."""
2+ from __future__ import annotations
3+
24import base64
35import hashlib
46import os
57import re
68import urllib .parse
9+ from uuid import uuid4
710
811AUTH_URL_HOSTNAME = "auth.simplisafe.com"
912AUTH_URL_BASE = f"https://{ AUTH_URL_HOSTNAME } "
1013AUTH_URL_LOGIN = f"{ AUTH_URL_BASE } /authorize"
1114
1215DEFAULT_AUTH0_CLIENT = (
13- "eyJuYW1lIjoiQXV0aDAuc3dpZnQiLCJlbnYiOnsiaU "
14- "9TIjoiMTUuMCIsInN3aWZ0IjoiNS54In0sInZlcnNpb24iOiIxLjMzLjAifQ "
16+ "eyJ2ZXJzaW9uIjoiMi4zLjIiLCJuYW1lIjoiQXV0aDAuc3dpZnQiLCJlbnYiOnsic3dpZnQiOiI1LngiLC "
17+ "JpT1MiOiIxNi4zIn19 "
1518)
1619DEFAULT_CLIENT_ID = "42aBZ5lYrVW12jfOuu3CQROitwxg9sN5"
1720DEFAULT_REDIRECT_URI = (
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