Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to latest Auth #6

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored URLs and Secrets to simplify any future updates.
  • Loading branch information
antgiant committed Nov 24, 2022
commit e047c9ef81ead13d56fb6781762cfc70738745a5
27 changes: 21 additions & 6 deletions owlet_api/owletapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
class OwletAPI():
"""Handles Owlet API stuff."""

owlet_login_url = 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k'
google_API_key = 'AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k'
app_id = 'owa-rg-id'
app_secret = 'owa-dx85qljgtR6hmVflyrL6LasCxA8'
owlet_login_url = 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key='
owlet_login_token_provider_url = 'https://ayla-sso.owletdata.com/mini/'
base_user_url = 'https://ads-owlue1.aylanetworks.com/api/v1/'
base_user_url = 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json'
base_properties_url = 'https://ads-owlue1.aylanetworks.com/apiv1/'

def __init__(self, email=None, password=None):
Expand All @@ -32,6 +35,18 @@ def __init__(self, email=None, password=None):
self._expiry_time = None
self._devices = []

def set_api_key(self, key):
"""Set google API key."""
self.google_API_key = key

def set_app_id(self, app_id):
"""Set app_id."""
self.app_id = app_id

def set_app_secret(self, app_secret):
"""Set app_secret."""
self.app_secret = app_secret

def set_email(self, email):
"""Set Email address aka Username."""
self._email = email
Expand All @@ -53,7 +68,7 @@ def login(self):
'Accept': 'application/json'
}

login_url = self.owlet_login_url
login_url = self.owlet_login_url + self.google_API_key



Expand Down Expand Up @@ -150,12 +165,12 @@ def login(self):
'Accept': 'application/json'
}

login_url = self.base_user_url + 'token_sign_in.json'
login_url = self.base_user_url

login_payload = {
'token': self._owlet_mini_token,
'app_id': 'owa-rg-id',
'app_secret': 'owa-dx85qljgtR6hmVflyrL6LasCxA8',
'app_id': self.app_id,
'app_secret': self.app_secret,
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json'
Expand Down
88 changes: 44 additions & 44 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
'metadata':{

},
'value':'https://ads-owlue1.aylanetworks.com/apiv1/devices/24826059/properties/LOGGED_DATA_CACHE/datapoints/76ce9810-5375-11e8-e7a5-6450803806ca.json',
'value':OwletAPI.base_properties_url + 'devices/24826059/properties/LOGGED_DATA_CACHE/datapoints/76ce9810-5375-11e8-e7a5-6450803806ca.json',
'created_at_from_device':None,
'file':'https://ayla-device-owlue1-production-1a2039d9.s3.amazonaws.com/X?AWSAccessKeyId=Y&Expires=1234&Signature=Z'
}
Expand All @@ -182,19 +182,19 @@

@responses.activate
def test_cli_token():
responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', 'token']):
cli()

@responses.activate
def test_cli_login_fail():
responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=400)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', 'token']):
Expand All @@ -215,45 +215,45 @@ def test_cli_server_down():

@responses.activate
def test_cli_devices_ok():
responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', 'devices']):
cli()

@responses.activate
def test_cli_attributes_ok():
responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=200)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', 'attributes']):
cli()

@responses.activate
def test_cli_download_ok():
responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=200)
responses.add(responses.GET, 'http://de.mo/file',
json=DOWNLOAD_DATA, status=200)
Expand All @@ -267,17 +267,17 @@ def test_cli_download_ok():
@responses.activate
def test_cli_stream_ok():

responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/apiv1/properties/42738119/datapoints',
responses.add(responses.POST, OwletAPI.base_properties_url + 'properties/42738119/datapoints',
status=201)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', '--timeout', '10', 'stream']):
Expand All @@ -287,19 +287,19 @@ def test_cli_stream_ok():
@responses.activate
def test_cli_stream_updatefail():

responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/apiv1/properties/42738119/datapoints',
responses.add(responses.POST, OwletAPI.base_properties_url + 'properties/42738119/datapoints',
status=201)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=400)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', '--timeout', '10', 'stream']):
Expand All @@ -309,17 +309,17 @@ def test_cli_stream_updatefail():
@responses.activate
def test_cli_stream_reactivationfail():

responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/apiv1/properties/42738119/datapoints',
responses.add(responses.POST, OwletAPI.base_properties_url + 'properties/42738119/datapoints',
status=400)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', '--timeout', '10', 'stream']):
Expand All @@ -331,17 +331,17 @@ def test_cli_stream_reactivationfail():
def test_cli_stream_ctrlc(sleep_mock):
sleep_mock.side_effect = SystemExit

responses.add(responses.POST, 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCBJ_5TRcPz_cQA4Xdqpcuo9PE5lR8Cc7k',
responses.add(responses.POST, OwletAPI.owlet_login_url + OwletAPI.google_API_key,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ayla-sso.owletdata.com/mini/',
responses.add(responses.GET, OwletAPI.owlet_login_token_provider_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/api/v1/token_sign_in.json',
responses.add(responses.POST, OwletAPI.base_user_url,
json=LOGIN_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/devices.json',
responses.add(responses.GET, OwletAPI.base_properties_url + 'devices.json',
json=DEVICES_PAYLOAD, status=200)
responses.add(responses.GET, 'https://ads-owlue1.aylanetworks.com/apiv1/dsns/c/properties',
responses.add(responses.GET, OwletAPI.base_properties_url + 'dsns/c/properties',
json=DEVICE_ATTRIBUTES, status=200)
responses.add(responses.POST, 'https://ads-owlue1.aylanetworks.com/apiv1/properties/42738119/datapoints',
responses.add(responses.POST, OwletAPI.base_properties_url + 'properties/42738119/datapoints',
status=201)

with patch('sys.argv', ['cli.py', 'test@test.de', 'moped', '--timeout', '10', 'stream']):
Expand Down
Loading