def test_build_authorize_endpoint(): client = OuraOAuth2Client("test_client", "test_secret") actual_url, state = client.authorize_endpoint(scope=["email", "daily"], state="foo") expected = "https://cloud.ouraring.com/oauth/authorize?response_type=code&client_id=test_client&scope=email+daily&state=foo" assert expected == actual_url assert "foo" == state
def test_token_request(): client = OuraOAuth2Client("test_client", "test_secret") fake_code = "fake_code" with requests_mock.mock() as m: m.post(client.TOKEN_BASE_URL, text=json.dumps({ 'access_token': 'fake_return_access_token', 'refresh_token': 'fake_return_refresh_token' })) retval = client.fetch_access_token(fake_code) assert "fake_return_access_token" == retval['access_token'] assert "fake_return_refresh_token" == retval['refresh_token']
def __init__(self, client_id, client_secret, redirect_uri='http://127.0.0.1:8080/'): self.success_html = """ <h1>You are now authorized to access the Oura API!</h1> <br/><h3>You can close this window</h3>""" self.failure_html = """<h1>ERROR: %s</h1><br/><h3>You can close this window</h3>%s""" self.oura_client = OuraOAuth2Client(client_id, client_secret) self.redirect_uri = redirect_uri
from ..api.datapull import refresh_database from sqlalchemy import delete import pandas as pd from dateutil.relativedelta import relativedelta from datetime import datetime import operator from ..api.fitlyAPI import hrv_training_workflow from ..app import app from flask import current_app as server import re from ..utils import config strava_auth_client = get_strava_client() withings_auth_client = NokiaAuth(config.get('withings', 'client_id'), config.get('withings', 'client_secret'), callback_uri=config.get('withings', 'redirect_uri')) oura_auth_client = OuraOAuth2Client(client_id=config.get('oura', 'client_id'), client_secret=config.get('oura', 'client_secret')) def get_layout(**kwargs): return html.Div([ html.Div(id='settings-layout'), html.Div(id='clear-log-dummy', style={'display': 'none'}), html.Div(id='token-dummy', style={'display': 'none'}), dbc.Modal(id="settings-modal", centered=True, autoFocus=True, fade=False, backdrop=True, size='sm', is_open=True, children=[ dbc.ModalHeader("Enter Admin Password"), dbc.ModalBody(className='text-center', children=[ dcc.Input(id='settings-password', type='password', placeholder='Password', value='')]), dbc.ModalFooter(html.Div([ dcc.Link(
try: auth_client.fetch_access_token(auth_code) print("Save these values!") for key, value in auth_client.session.token.items(): print('{} = {}'.format(key, value)) return "<h1>You are now authorized to access the Oura API!</h1>" except Exception as e: print(e) return "<h1>Error retrieving a token {}</h1>".format(e) def browser_authorize(auth_client): url, _ = auth_client.authorize_endpoint() threading.Timer(1, webbrowser.open, args=(url, )).start() if __name__ == '__main__': if not (len(sys.argv) == 3): print("Arguments: client_id and client_secret") sys.exit(1) os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = "1" auth_client = OuraOAuth2Client(*sys.argv[1:]) browser_authorize(auth_client) # test_response = server.oura.user_info() app.run(debug=False, host='0.0.0.0', port=3030) input("Press any key to close")
from dash_app import dash_app import dash_core_components as dcc from lib.ouraAPI import oura_connected, connect_oura_link from oura import OuraOAuth2Client from lib.ouraAPI import save_oura_token import configparser import re import time config = configparser.ConfigParser() config.read('config.ini') client_id = config.get('oura', 'client_id') client_secret = config.get('oura', 'client_secret') auth_client = OuraOAuth2Client(client_id=client_id, client_secret=client_secret) layout = html.Div(id='oura-auth-canvas', children=[ html.Div(id='oura-token-refresh', style={'display': 'none'}), dcc.Loading(html.Div(id='oura-auth-layout')) ]) def test_oura_connection(): time.sleep(3) if not oura_connected(): return html.Div(style={'textAlign': 'center'}, className='twelve columns', children=[ html.A(html.Button('Connect'), href=connect_oura_link(auth_client)) ]) else: