fix: redirect uri auf https umstellen mit self-signed cert
This commit is contained in:
@@ -14,7 +14,7 @@ Terminal-basierter Spotify Client im Stil von ncmpcpp.
|
|||||||
|
|
||||||
1. Gehe zu https://developer.spotify.com/dashboard
|
1. Gehe zu https://developer.spotify.com/dashboard
|
||||||
2. Erstelle eine neue App
|
2. Erstelle eine neue App
|
||||||
3. Setze den Redirect URI auf `http://localhost:8888/callback`
|
3. Setze den Redirect URI auf `https://localhost:8888/callback`
|
||||||
4. Kopiere die **Client ID**
|
4. Kopiere die **Client ID**
|
||||||
|
|
||||||
### 2. Installation
|
### 2. Installation
|
||||||
|
|||||||
+26
-3
@@ -83,7 +83,7 @@ class SpotifyAuth:
|
|||||||
params = {
|
params = {
|
||||||
"client_id": self.client_id,
|
"client_id": self.client_id,
|
||||||
"response_type": "code",
|
"response_type": "code",
|
||||||
"redirect_uri": "http://localhost:8888/callback",
|
"redirect_uri": "https://localhost:8888/callback",
|
||||||
"code_challenge_method": "S256",
|
"code_challenge_method": "S256",
|
||||||
"code_challenge": code_challenge,
|
"code_challenge": code_challenge,
|
||||||
"state": state,
|
"state": state,
|
||||||
@@ -104,7 +104,27 @@ class SpotifyAuth:
|
|||||||
|
|
||||||
def _wait_for_callback(self, timeout=300):
|
def _wait_for_callback(self, timeout=300):
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
import threading
|
import ssl
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
cert_dir = self.cfg.get("cert_dir", "")
|
||||||
|
if not cert_dir:
|
||||||
|
from pathlib import Path
|
||||||
|
cert_dir = str(Path.home() / ".config" / "spotify-cli" / "certs")
|
||||||
|
self.cfg["cert_dir"] = cert_dir
|
||||||
|
|
||||||
|
cert_file = f"{cert_dir}/cert.pem"
|
||||||
|
key_file = f"{cert_dir}/key.pem"
|
||||||
|
|
||||||
|
import os
|
||||||
|
if not os.path.exists(cert_file) or not os.path.exists(key_file):
|
||||||
|
os.makedirs(cert_dir, exist_ok=True)
|
||||||
|
subprocess.run([
|
||||||
|
"openssl", "req", "-x509", "-newkey", "rsa:2048",
|
||||||
|
"-keyout", key_file, "-out", cert_file,
|
||||||
|
"-days", "365", "-nodes",
|
||||||
|
"-subj", "/CN=localhost"
|
||||||
|
], check=True, capture_output=True)
|
||||||
|
|
||||||
received_code = {"code": None, "state": None}
|
received_code = {"code": None, "state": None}
|
||||||
|
|
||||||
@@ -128,6 +148,9 @@ class SpotifyAuth:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
server = HTTPServer(("localhost", 8888), Handler)
|
server = HTTPServer(("localhost", 8888), Handler)
|
||||||
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||||
|
ctx.load_cert_chain(cert_file, key_file)
|
||||||
|
server.socket = ctx.wrap_socket(server.socket, server_side=True)
|
||||||
server.timeout = timeout
|
server.timeout = timeout
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
@@ -143,7 +166,7 @@ class SpotifyAuth:
|
|||||||
resp = requests.post(SPOTIFY_TOKEN_URL, data={
|
resp = requests.post(SPOTIFY_TOKEN_URL, data={
|
||||||
"grant_type": "authorization_code",
|
"grant_type": "authorization_code",
|
||||||
"code": code,
|
"code": code,
|
||||||
"redirect_uri": "http://localhost:8888/callback",
|
"redirect_uri": "https://localhost:8888/callback",
|
||||||
"client_id": self.client_id,
|
"client_id": self.client_id,
|
||||||
"code_verifier": code_verifier,
|
"code_verifier": code_verifier,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user