MattTW / BlinkMonitorProtocol

Unofficial documentation for the Blink Wire-Free HD Home Monitoring & Alert System
443 stars 82 forks source link

{'message': 'Unauthorized Access', 'code': 101} #71

Closed sim2511 closed 1 year ago

sim2511 commented 1 year ago

Hello,

I have trouble to connect to homescreen api, error i received (second block of my code) : {'message': 'Unauthorized Access', 'code': 101}. I use the token_auth I received from first block, what am i doing wrong ? Regards

url = "https://rest-prod.immedia-semi.com/api/v5/account/login"

# Préparez les données à envoyer avec la requête
data = {
    "email": username,
    "password": password,
    "client_specifier": "iPhone 9.2 | 2.2 | 222"
}

# Envoyez la requête à l'API de Blink
response = requests.post(url, json=data)

# Vérifiez si la connexion a réussi
if response.status_code == 200:
    # Si la connexion a réussi, extraire le token d'authentification et le client_id
    auth_token = response.json().get("auth").get("token")
    client_id = response.json().get("account").get("client_id")
    account_id = response.json().get("account").get("account_id")
    region = response.json().get("account").get("region")
    print(response.json())
    print("region :", region)
    print("account_id ", account_id)
    print("Auth token: ", auth_token)
    print("Client id: ", client_id)

else:
    print("Failed to log in:", response.content)

try:
    url_homescreen=f"https://rest-prod.immedia-semi.com/api/v3/accounts/{account_id}/homescreen"
    headers = {"token-auth": auth_token}
    response_homescreen = requests.get(url_homescreen, headers=headers)
    print(response_homescreen.json())
except Exception as e:
    print(f"Erreur lors de l'authentification : {e}")
sim2511 commented 1 year ago

My response.json() (formated)

{'account': {'account_id': x user_id': x client_id': x client_trusted': False new_account': True tier': 'x' region': 'eu' account_verification_required': False phone_verification_required': False client_verification_required': True require_trust_client_device': True country_required': False verification_channel': 'phone' user': {'user_id': x country': 'x'} amazon_account_linked': True braze_external_id': 'x'} auth': {'token': 'x'} phone': {'number': '+' last_4_digits': 'x' country_calling_code': 'x' valid': True} verification': {'email': {'required': False} phone': {'required': True channel': 'sms'}} lockout_time_remaining': 0 force_password_reset': False allow_pin_resend_seconds': 90}

sim2511 commented 1 year ago

I also change my url https://rest-**e004.**immedia-semi.com/api/v3/accounts/{account_id}/homescreen but still unable to connect :(

sim2511 commented 1 year ago

Does client_trusted': False has any impact? How can I change this?

sim2511 commented 1 year ago
username = username_entry.get()
password = password_entry.get()
# login
data = {
    "email": username,
    "password": password,
    "device_identifier": "****",
    "client_name": "Simon's camera",
    "reauth": True,
}
response = requests.post(f"https://rest-prod.immedia-semi.com/api/v5/account/login", json=data)

if response.status_code == 200:
    auth_token = response.json().get("auth").get("token")
    client_id = response.json().get("account").get("client_id")
    account_id = response.json().get("account").get("account_id")
    region = response.json().get("account").get("region")
    tier= response.json().get("account").get("tier")
    print(response.json())
else:
    print("Failed to log in:", response.content)

# ask for the pincode
pincode = input("Enter pincode:")

# verify pin
data = {
    "pin": pincode
}
headers = {'token-auth': auth_token}
response = requests.post(f"https://rest-{tier}.immedia-semi.com/api/v4/account/{account_id}/client/{client_id}/pin/verify", json=data, headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print("Failed to verify pin:", response.content)

headers = {'token-auth': auth_token}
response = requests.get(f"https://rest-{tier}.immedia-semi.com/api/v3/accounts/{account_id}/homescreen", headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print("Failed to get data from homescreen:", response.content)
sim2511 commented 1 year ago

The solution is the code above