Upgraded login endpoint, fixed uid generation

This commit is contained in:
Kevin Fronczak
2021-02-11 11:21:26 -05:00
parent 6fa4aa6f75
commit 9e793b6748
6 changed files with 20 additions and 19 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: [3.8] python-version: [3.9]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
+5 -5
View File
@@ -129,11 +129,11 @@ class Auth:
def extract_login_info(self): def extract_login_info(self):
"""Extract login info from login response.""" """Extract login info from login response."""
self.region_id = self.login_response["region"]["tier"] self.region_id = self.login_response["account"]["tier"]
self.host = f"{self.region_id}.{BLINK_URL}" self.host = f"{self.region_id}.{BLINK_URL}"
self.token = self.login_response["authtoken"]["authtoken"] self.token = self.login_response["auth"]["token"]
self.client_id = self.login_response["client"]["id"] self.client_id = self.login_response["account"]["client_id"]
self.account_id = self.login_response["account"]["id"] self.account_id = self.login_response["account"]["account_id"]
def startup(self): def startup(self):
"""Initialize tokens for communication.""" """Initialize tokens for communication."""
@@ -242,7 +242,7 @@ class Auth:
def check_key_required(self): def check_key_required(self):
"""Check if 2FA key is required.""" """Check if 2FA key is required."""
try: try:
if self.login_response["client"]["verification_required"]: if self.login_response["account"]["client_verification_required"]:
return True return True
except (KeyError, TypeError): except (KeyError, TypeError):
pass pass
+2 -2
View File
@@ -4,7 +4,7 @@ import os
MAJOR_VERSION = 0 MAJOR_VERSION = 0
MINOR_VERSION = 16 MINOR_VERSION = 16
PATCH_VERSION = "5.rc0" PATCH_VERSION = "5.rc1"
__version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}" __version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"
@@ -49,7 +49,7 @@ URLS
BLINK_URL = "immedia-semi.com" BLINK_URL = "immedia-semi.com"
DEFAULT_URL = f"rest-prod.{BLINK_URL}" DEFAULT_URL = f"rest-prod.{BLINK_URL}"
BASE_URL = f"https://{DEFAULT_URL}" BASE_URL = f"https://{DEFAULT_URL}"
LOGIN_ENDPOINT = f"{BASE_URL}/api/v4/account/login" LOGIN_ENDPOINT = f"{BASE_URL}/api/v5/account/login"
""" """
Dictionaries Dictionaries
+7 -4
View File
@@ -33,10 +33,13 @@ def json_save(data, file_name):
json.dump(data, json_file, indent=4) json.dump(data, json_file, indent=4)
def gen_uid(size): def gen_uid(size, uid_format=False):
"""Create a random sring.""" """Create a random sring."""
full_token = secrets.token_hex(size) if uid_format:
return full_token[0:size] token = f"{secrets.token_hex(8)}-{secrets.token_hex(4)}-{secrets.token_hex(4)}-{secrets.token_hex(4)}-{secrets.token_hex(12)}"
else:
token = secrets.token_hex(size)
return token
def time_to_seconds(timestamp): def time_to_seconds(timestamp):
@@ -79,7 +82,7 @@ def prompt_login_data(data):
def validate_login_data(data): def validate_login_data(data):
"""Check for missing keys.""" """Check for missing keys."""
data["uid"] = data.get("uid", gen_uid(const.SIZE_UID)) data["uid"] = data.get("uid", gen_uid(const.SIZE_UID, uid_format=True))
data["notification_key"] = data.get( data["notification_key"] = data.get(
"notification_key", gen_uid(const.SIZE_NOTIFICATION_KEY) "notification_key", gen_uid(const.SIZE_NOTIFICATION_KEY)
) )
+4 -6
View File
@@ -165,10 +165,8 @@ class TestAuth(unittest.TestCase):
def test_refresh_token(self, mock_login): def test_refresh_token(self, mock_login):
"""Test refresh token method.""" """Test refresh token method."""
mock_login.return_value = { mock_login.return_value = {
"region": {"tier": "test"}, "account": {"account_id": 5678, "client_id": 1234, "tier": "test"},
"authtoken": {"authtoken": "foobar"}, "auth": {"token": "foobar"},
"client": {"id": 1234},
"account": {"id": 5678},
} }
self.assertTrue(self.auth.refresh_token()) self.assertTrue(self.auth.refresh_token())
self.assertEqual(self.auth.region_id, "test") self.assertEqual(self.auth.region_id, "test")
@@ -190,10 +188,10 @@ class TestAuth(unittest.TestCase):
self.auth.login_response = {} self.auth.login_response = {}
self.assertFalse(self.auth.check_key_required()) self.assertFalse(self.auth.check_key_required())
self.auth.login_response = {"client": {"verification_required": False}} self.auth.login_response = {"account": {"client_verification_required": False}}
self.assertFalse(self.auth.check_key_required()) self.assertFalse(self.auth.check_key_required())
self.auth.login_response = {"client": {"verification_required": True}} self.auth.login_response = {"account": {"client_verification_required": True}}
self.assertTrue(self.auth.check_key_required()) self.assertTrue(self.auth.check_key_required())
@mock.patch("blinkpy.auth.api.request_verify") @mock.patch("blinkpy.auth.api.request_verify")
+1 -1
View File
@@ -1,5 +1,5 @@
[tox] [tox]
envlist = build, py36, py37, py38, lint envlist = build, py36, py37, py38, py39, lint
skip_missing_interpreters = True skip_missing_interpreters = True
skipsdist = True skipsdist = True