From 071eae8df4c83885a228a0d06da831db465a3977 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 2 Dec 2022 11:44:05 -0800 Subject: [PATCH 1/2] Fix oauth_callback write of token to local storate Update local webserver to run on 0.0.0.0 by default Add flask to requirements.txt --- ovos_config_assistant/app.py | 12 +++++++----- requirements/requirements.txt | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ovos_config_assistant/app.py b/ovos_config_assistant/app.py index c81fc58..e0c81b6 100644 --- a/ovos_config_assistant/app.py +++ b/ovos_config_assistant/app.py @@ -24,7 +24,8 @@ def oauth_callback(oauth_id): params = dict(request.args) code = params["code"] - data = JsonStorageXDG("ovos_oauth_apps")[oauth_id] + oauth_store = JsonStorageXDG("ovos_oauth_apps") + data = oauth_store[oauth_id] client_id = data["client_id"] client_secret = data["client_secret"] token_endpoint = data["token_endpoint"] @@ -43,13 +44,14 @@ def oauth_callback(oauth_id): data=body, auth=(client_id, client_secret), ).json() - - with JsonStorageXDG("ovos_oauth") as db: - db.add_token(oauth_id, token_response) + print(oauth_id) + print(token_response) + data['token_response'] = token_response + oauth_store.store() return params def main(port=36535, debug=True): - app.run(port=port, debug=debug) + app.run(host='0.0.0.0', port=port, debug=debug) # start_server(start, port=port, debug=debug) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 1609ffa..77c96c7 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -2,4 +2,5 @@ ovos_utils pywebio cutecharts oauthlib~=3.0 -ovos_backend_client \ No newline at end of file +ovos_backend_client +flask~=2.2 \ No newline at end of file From 7223d8fa49af74b33120709f714d34914a7636e4 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Mon, 5 Dec 2022 14:21:51 -0800 Subject: [PATCH 2/2] Cleanup changes --- ovos_config_assistant/app.py | 49 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/ovos_config_assistant/app.py b/ovos_config_assistant/app.py index e0c81b6..3939086 100644 --- a/ovos_config_assistant/app.py +++ b/ovos_config_assistant/app.py @@ -24,34 +24,31 @@ def oauth_callback(oauth_id): params = dict(request.args) code = params["code"] - oauth_store = JsonStorageXDG("ovos_oauth_apps") - data = oauth_store[oauth_id] - client_id = data["client_id"] - client_secret = data["client_secret"] - token_endpoint = data["token_endpoint"] - - # Prepare and send a request to get tokens! Yay tokens! - client = WebApplicationClient(client_id) - token_url, headers, body = client.prepare_token_request( - token_endpoint, - authorization_response=request.url, - redirect_url=request.base_url, - code=code - ) - token_response = requests.post( - token_url, - headers=headers, - data=body, - auth=(client_id, client_secret), - ).json() - print(oauth_id) - print(token_response) - data['token_response'] = token_response - oauth_store.store() + with JsonStorageXDG("ovos_oauth_apps") as oauth_store: + data = oauth_store[oauth_id] + client_id = data["client_id"] + client_secret = data["client_secret"] + token_endpoint = data["token_endpoint"] + + # Prepare and send a request to get tokens! Yay tokens! + client = WebApplicationClient(client_id) + token_url, headers, body = client.prepare_token_request( + token_endpoint, + authorization_response=request.url, + redirect_url=request.base_url, + code=code + ) + token_response = requests.post( + token_url, + headers=headers, + data=body, + auth=(client_id, client_secret), + ).json() + data['token_response'] = token_response return params -def main(port=36535, debug=True): - app.run(host='0.0.0.0', port=port, debug=debug) +def main(host='0.0.0.0', port=36535, debug=True): + app.run(host=host, port=port, debug=debug) # start_server(start, port=port, debug=debug)