Skip to content

Instantly share code, notes, and snippets.

@Wh1terat
Last active September 10, 2021 14:57
Show Gist options
  • Save Wh1terat/71eaf8a43b1665e46a601cfb74a6ed6b to your computer and use it in GitHub Desktop.
Save Wh1terat/71eaf8a43b1665e46a601cfb74a6ed6b to your computer and use it in GitHub Desktop.
CleverSpa - Get Auth Token and Device IDs
#!/usr/bin/env python3
import requests
from getpass import getpass
GOOGLE_AUTH_URL = (
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword"
)
GOOGLE_AUTH_KEY = "AIzaSyByDiPaSuvWgnB61aSoseEcE292UcUg_Xg"
FIREBASE_DB = "https://cleverspa-2e6a6.firebaseio.com"
GIZWITS_API_URL = "https://api.gizwits.com/app"
headers = {
"X-Gizwits-Application-Id": "805cc6a3f41b48aeae471e2fcb6ebc73",
}
def login(email, password):
try:
user = requests.post(
GOOGLE_AUTH_URL,
params={"key": GOOGLE_AUTH_KEY},
json={"email": email, "password": password, "returnSecureToken": True},
)
user.raise_for_status()
except requests.exceptions.HTTPError as error:
error = error.response.json()
print("{code} - {message}".format(**error["error"]))
return False
user = user.json()
try:
info = requests.get(
f"{FIREBASE_DB}/users/{user['localId']}.json",
params={"auth": user["idToken"]},
)
info.raise_for_status()
except requests.exceptions.HTTPError as error:
error = error.response.json()
print("{code} - {message}".format(**error["error"]))
return False
info = info.json()
headers["X-Gizwits-User-token"] = info["token"]
return True
def get_devices():
try:
devices = requests.get(f"{GIZWITS_API_URL}/bindings", headers=headers)
devices.raise_for_status()
except requests.exceptions.HTTPError as error:
error = error.response.json()
print("{error_code} - {error_message}".format(**error))
return []
devices = devices.json().get("devices", [])
return devices
def main():
user = input("CleverSpa E-mail: ")
pswd = getpass("CleverSpa Password: ")
if user and pswd:
if login(user, pswd):
print(f"Auth-Token:{headers['X-Gizwits-User-token']}")
for device in get_devices():
print("{product_name} - DID:{did} - MAC:{mac}".format(**device))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment