Add UI to configure Spotify Client ID in Settings
- Add expandable Configuration section in Spotify settings - Store Client ID in UserDefaults - Show Connect button only when Client ID is configured - Add helper text pointing to Spotify Developer Dashboard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,6 @@ import Foundation
|
||||
import os
|
||||
|
||||
enum SpotifyConfig {
|
||||
static let clientId = "YOUR_SPOTIFY_CLIENT_ID"
|
||||
static let redirectUri = "iris-spotify-auth://callback"
|
||||
static let scopes = "user-read-playback-state user-read-currently-playing"
|
||||
static let authUrl = "https://accounts.spotify.com/authorize"
|
||||
@@ -24,17 +23,31 @@ final class SpotifyAuthManager: NSObject, ObservableObject {
|
||||
@Published private(set) var isConnected: Bool = false
|
||||
@Published private(set) var isAuthenticating: Bool = false
|
||||
@Published private(set) var error: String? = nil
|
||||
@Published private(set) var clientId: String = ""
|
||||
|
||||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "iris", category: "SpotifyAuth")
|
||||
private let tokensKey = "spotify_tokens"
|
||||
private let clientIdKey = "spotify_client_id"
|
||||
private var codeVerifier: String? = nil
|
||||
private var authSession: ASWebAuthenticationSession? = nil
|
||||
|
||||
var isConfigured: Bool {
|
||||
!clientId.isEmpty
|
||||
}
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
clientId = UserDefaults.standard.string(forKey: clientIdKey) ?? ""
|
||||
loadTokens()
|
||||
}
|
||||
|
||||
func setClientId(_ id: String) {
|
||||
let trimmed = id.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
clientId = trimmed
|
||||
UserDefaults.standard.set(trimmed, forKey: clientIdKey)
|
||||
logger.info("Spotify Client ID updated")
|
||||
}
|
||||
|
||||
var accessToken: String? {
|
||||
loadStoredTokens()?.accessToken
|
||||
}
|
||||
@@ -50,7 +63,7 @@ final class SpotifyAuthManager: NSObject, ObservableObject {
|
||||
|
||||
var components = URLComponents(string: SpotifyConfig.authUrl)!
|
||||
components.queryItems = [
|
||||
URLQueryItem(name: "client_id", value: SpotifyConfig.clientId),
|
||||
URLQueryItem(name: "client_id", value: clientId),
|
||||
URLQueryItem(name: "response_type", value: "code"),
|
||||
URLQueryItem(name: "redirect_uri", value: SpotifyConfig.redirectUri),
|
||||
URLQueryItem(name: "scope", value: SpotifyConfig.scopes),
|
||||
@@ -145,7 +158,7 @@ final class SpotifyAuthManager: NSObject, ObservableObject {
|
||||
"grant_type": "authorization_code",
|
||||
"code": code,
|
||||
"redirect_uri": SpotifyConfig.redirectUri,
|
||||
"client_id": SpotifyConfig.clientId,
|
||||
"client_id": clientId,
|
||||
"code_verifier": verifier
|
||||
]
|
||||
|
||||
@@ -172,7 +185,7 @@ final class SpotifyAuthManager: NSObject, ObservableObject {
|
||||
let body = [
|
||||
"grant_type": "refresh_token",
|
||||
"refresh_token": refreshToken,
|
||||
"client_id": SpotifyConfig.clientId
|
||||
"client_id": clientId
|
||||
]
|
||||
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user