From 1bf083ae0d061146c7593ff4cdb77d6086db5a6b Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Tue, 28 Apr 2026 18:25:08 +0200 Subject: [PATCH] Add endpoint for handling Amazon token exchange --- cmd/soundtouch-service/main.go | 3 ++- .../testdata/router_routes.txt | 1 + pkg/service/handlers/handlers_oauth.go | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cmd/soundtouch-service/main.go b/cmd/soundtouch-service/main.go index b596e71..2c1e983 100644 --- a/cmd/soundtouch-service/main.go +++ b/cmd/soundtouch-service/main.go @@ -871,9 +871,10 @@ func setupRouter(server *handlers.Server) *chi.Mux { }) r.Route("/oauth", func(r chi.Router) { - r.Post("/device/{deviceID}/music/musicprovider/{sourceID}/token/cs3", server.HandleBoseToken) r.Post("/device/{deviceID}/music/musicprovider/{sourceID}/token", server.HandleBoseLegacyToken) r.Post("/account/{account}/music/musicprovider/{sourceID}/token/cs", server.HandleBoseAccountToken) + r.Post("/device/{deviceID}/music/musicprovider/{sourceID}/token/cs1", server.HandleBoseToken) + r.Post("/device/{deviceID}/music/musicprovider/{sourceID}/token/cs3", server.HandleBoseToken) r.HandleFunc("/*", server.HandleBoseProxy) }) diff --git a/cmd/soundtouch-service/testdata/router_routes.txt b/cmd/soundtouch-service/testdata/router_routes.txt index ea2622e..170f07a 100644 --- a/cmd/soundtouch-service/testdata/router_routes.txt +++ b/cmd/soundtouch-service/testdata/router_routes.txt @@ -102,6 +102,7 @@ POST /mgmt/spotify/prime handlers.( POST /oauth/* handlers.(*Server).HandleBoseProxy-fm POST /oauth/account/{account}/music/musicprovider/{sourceID}/token/cs handlers.(*Server).HandleBoseAccountToken-fm POST /oauth/device/{deviceID}/music/musicprovider/{sourceID}/token handlers.(*Server).HandleBoseLegacyToken-fm +POST /oauth/device/{deviceID}/music/musicprovider/{sourceID}/token/cs1 handlers.(*Server).HandleBoseToken-fm POST /oauth/device/{deviceID}/music/musicprovider/{sourceID}/token/cs3 handlers.(*Server).HandleBoseToken-fm POST /setup/backup/{deviceId} handlers.(*Server).HandleBackupConfig-fm POST /setup/devices handlers.(*Server).HandleAddManualDevice-fm diff --git a/pkg/service/handlers/handlers_oauth.go b/pkg/service/handlers/handlers_oauth.go index c145740..992a768 100644 --- a/pkg/service/handlers/handlers_oauth.go +++ b/pkg/service/handlers/handlers_oauth.go @@ -14,14 +14,23 @@ import ( ) // HandleBoseToken handles the Bose-specific token refresh request from the speaker. +// POST /oauth/device/{deviceID}/music/musicprovider/{sourceID}/token/cs1 // POST /oauth/device/{deviceID}/music/musicprovider/{sourceID}/token/cs3 func (s *Server) HandleBoseToken(w http.ResponseWriter, r *http.Request) { sourceID := chi.URLParam(r, "sourceID") for _, provider := range constants.StaticProviders { - if strconv.Itoa(provider.ID) == sourceID && provider.Name == constants.ProviderSpotify { + if strconv.Itoa(provider.ID) != sourceID { + continue + } + + switch provider.Name { + case constants.ProviderSpotify: s.HandleBoseSpotifyToken(w, r) return + case constants.ProviderAmazon: + s.HandleBoseAmazonToken(w, r) + return } } @@ -89,6 +98,15 @@ func (s *Server) HandleBoseAccountToken(w http.ResponseWriter, r *http.Request) s.HandleBoseSpotifyToken(w, r) } +// HandleBoseAmazonToken is a stub for Amazon Music OAuth token handling. +// POST /oauth/device/{deviceID}/music/musicprovider/20/token/cs1 +// Amazon Music API integration is not yet implemented. +func (s *Server) HandleBoseAmazonToken(w http.ResponseWriter, r *http.Request) { + deviceID := chi.URLParam(r, "deviceID") + log.Printf("[Amazon] Token request for device %s — Amazon Music not yet supported", deviceID) + http.Error(w, "Amazon Music integration not yet supported", http.StatusNotImplemented) +} + // HandleBoseSpotifyToken handles the Bose-specific Spotify token refresh request. // POST /oauth/device/{deviceID}/music/musicprovider/15/token/cs3 func (s *Server) HandleBoseSpotifyToken(w http.ResponseWriter, r *http.Request) {