From 14ee7ef987e0bb83c5d0fb2170b3f47a9ae35fb6 Mon Sep 17 00:00:00 2001 From: Alfie King Date: Sun, 1 Sep 2024 18:27:56 +0100 Subject: [PATCH] fix auth --- src/main.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main.py b/src/main.py index 096ce42..865fef6 100644 --- a/src/main.py +++ b/src/main.py @@ -37,16 +37,6 @@ def get_auth(): }) redirect = requests.get(f"https://accounts.spotify.com/authorize?{query}") print(redirect.url) - code = input('Enter code: ') - data = requests.post('https://accounts.spotify.com/api/token', data={ - 'grant_type': 'authorization_code', - 'code': code, - 'redirect_uri': os.getenv('REDIRECT_URI'), - }, headers={ - 'content-type': 'application/x-www-form-urlencoded', - 'Authorization': 'Basic ' + base64.b64encode(f"{os.getenv('CLIENT_ID')}:{os.getenv('CLIENT_SECRET')}".encode()).decode() - }).json() - save_cache(data) return True def update_token(): @@ -64,6 +54,20 @@ def update_token(): # Routes +@app.route('/api/auth', methods=['GET']) +def auth(): + code = request.args.get('code') + data = requests.post('https://accounts.spotify.com/api/token', data={ + 'grant_type': 'authorization_code', + 'code': code, + 'redirect_uri': os.getenv('REDIRECT_URI'), + }, headers={ + 'content-type': 'application/x-www-form-urlencoded', + 'Authorization': 'Basic ' + base64.b64encode(f"{os.getenv('CLIENT_ID')}:{os.getenv('CLIENT_SECRET')}".encode()).decode() + }).json() + save_cache(data) + return "Authenticated" + @app.route('/api/nowplaying', methods=['GET']) def nowplaying(): cache = get_cache()