From cca8dae39a516cd7a5d88be95f3ccf4e836e0146 Mon Sep 17 00:00:00 2001 From: barry Date: Wed, 2 Sep 2026 17:26:15 +0200 Subject: [PATCH] add first auth script --- spotiplayer_pi/first_auth.py | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spotiplayer_pi/first_auth.py diff --git a/spotiplayer_pi/first_auth.py b/spotiplayer_pi/first_auth.py new file mode 100644 index 0000000..52a5065 --- /dev/null +++ b/spotiplayer_pi/first_auth.py @@ -0,0 +1,46 @@ +import requests +import webbrowser +from urllib.parse import urlencode, urlparse, parse_qs +import base64 + + +CLIENT_ID = input("YOUR_CLIENT_ID: ") +CLIENT_SECRET = input("YOUR_CLIENT_SECRET: ") +BASE_64 = base64.b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode()).decode() +REDIRECT_URI = "http://127.0.0.1:8888/callback" +SCOPE = "user-read-private user-read-email" + +webbrowser.open( + "https://accounts.spotify.com/authorize?" + + urlencode( + { + "client_id": CLIENT_ID, + "response_type": "code", + "redirect_uri": REDIRECT_URI, + "scope": SCOPE, + } + ) +) + +url = input("Paste FULL callback URL: ").strip() +code = parse_qs(urlparse(url).query)["code"][0] + +r = requests.post( + "https://accounts.spotify.com/api/token", + auth=(CLIENT_ID, CLIENT_SECRET), + data={ + "grant_type": "authorization_code", + "code": code, + "redirect_uri": REDIRECT_URI, + }, +) +r.raise_for_status() +tokens = r.json() + +print("-" * 20) +print("ACCESS TOKEN :", tokens["access_token"]) +print("REFRESH TOKEN:", tokens["refresh_token"]) +print( + "BASE64:", BASE_64 +) # TODO set these automatically in config.yaml, auto update when expired +print("-" * 20)