badaix / snapcast

Synchronous multiroom audio player
GNU General Public License v3.0
6.09k stars 452 forks source link

Spotify Password Authentication Deprecated #1274

Open goshansp opened 3 weeks ago

goshansp commented 3 weeks ago

Describe the bug Some users have been getting [Error] (librespot) could not initialize spirc: Permission denied { Login failed with reason: Bad credentials } in the past weeks. It seems that Spotify is deprecating password authentication as notified to Librespot.

It seems that snapcast needs to implement the new token based authentication mechanism as soon as this change in librespot gets merged.

Steps to Reproduce

  1. Configure Spotify Username & Password
  2. Start Snapcast

Environment details

[Error] (librespot) could not initialize spirc: Permission denied { Login failed with reason: Bad credentials }
awsome306 commented 3 weeks ago

Is there anything to do in the meantime? Or is it just to wait until the changes get merged?

acaliebe commented 3 weeks ago

Try to Play with zeroconf - without username and password. -- and wait for Librespot to solve the problem.

/usr/bin/librespot --name MyLibrespotSpeaker --bitrate 320 --backend pipe --cache /var/cache/librespot --initial-volume 100 --verbose

_[2024-08-19T12:18:50Z INFO librespot] librespot 0.5.0-dev 299b7de (Built on 2024-08-14, Build ID: OsvPSZhj, Profile: release) [2024-08-19T12:18:50Z TRACE librespot] Command line argument(s): [2024-08-19T12:18:50Z TRACE librespot] name "MyLibrespotSpeaker" [2024-08-19T12:18:50Z TRACE librespot] bitrate "320" [2024-08-19T12:18:50Z TRACE librespot] backend "pipe" [2024-08-19T12:18:50Z TRACE librespot] cache "/var/cache/librespot" [2024-08-19T12:18:50Z TRACE librespot] initial-volume "100" [2024-08-19T12:18:50Z TRACE librespot] onevent "/usr/bin/librespot_event" [2024-08-19T12:18:50Z TRACE librespot] verbose [2024-08-19T12:18:50Z TRACE librespot] Using cached credentials. [2024-08-19T12:18:50Z DEBUG librespot_core::session] new Session [2024-08-19T12:18:50Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:34245 [2024-08-19T12:18:50Z INFO librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0) [2024-08-19T12:18:50Z DEBUG librespot_playback::player] new Player [0] [2024-08-19T12:18:50Z DEBUG librespot_connect::spirc] new Spirc[0] [2024-08-19T12:18:50Z INFO librespot_playback::convert] Converting with ditherer: tpdf [2024-08-19T12:18:50Z DEBUG librespot::component] new MercuryManager [2024-08-19T12:18:50Z INFO librespot_playback::audio_backend::pipe] Using StdoutSink (pipe) with format: S16 [2024-08-19T12:18:50Z DEBUG librespot::component] new ApResolver [2024-08-19T12:18:50Z DEBUG librespot_core::http_client] Requesting https://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient [2024-08-19T12:18:50Z DEBUG librespot_playback::player] command=AddEventSender [2024-08-19T12:18:51Z INFO librespot_core::session] Connecting to AP "ap-gew4.spotify.com:4070" [2024-08-19T12:18:51Z INFO librespot_core::session] Authenticated as "anycryptedname" ! [2024-08-19T12:18:51Z DEBUG librespot_connect::spirc] canonical_username: anycryptedname [2024-08-19T12:18:51Z DEBUG librespot_playback::player] command=AddEventSender [2024-08-19T12:18:51Z DEBUG librespot_core::mercury] listening to uri=hm://remote/user/ [2024-08-19T12:18:51Z DEBUG librespot_core::mercury] listening to uri=spotify:user:attributes:update [2024-08-19T12:18:51Z DEBUG librespot_core::mercury] listening to uri=spotify:user:attributes:mutated [2024-08-19T12:18:51Z DEBUG librespot_core::mercury] listening to uri=hm://pusher/v1/connections/ [2024-08-19T12:18:51Z DEBUG librespot_core::session] Session strong=4 weak=4 [2024-08-19T12:18:51Z INFO librespot_core::session] Country: "DE" [2024-08-19T12:18:51Z TRACE librespotcore::session] Received product info: ....

Snapserver source sample ( in /etc/snapserver.conf ): source = spotify:///librespot?name=Spotify&dryout_ms=2000&wd_timeout=7800&controlscript=librespot_meta.sh&devicename=MySnapServer&cache=/var/cache/librespot&cache-size-limit=2G&onevent=/usr/bin/librespot_event&bitrate=320&volume=100&killall=true

notes:

bai-yi-bai commented 3 weeks ago

I just wanted to report that I am a snapcast user and I had my Spotify account disabled due to password-based credentials being deprecated by what I suppose is either my Home Assistant snapcast integration or snapcast server hammering spotify trying to log in . I had the same [Error] (librespot) could not initialize spirc: Permission denied { Login failed with reason: Bad credentials }. I used acaliebe's suggestion:

  1. Go to spotify to request a password reset.
  2. [Fixing Home Assistant] I re-copied the client id and client secret using Home Assistant's nifty integration which uses URLs https://www.home-assistant.io/integrations/spotify
  3. [Android App] I had to clear the cache and database otherwise, I couldn't log in, I had three large dots.
  4. [snapserver.conf] I removed the ?username= and ?password= portions
  5. I started playback and had to restart a couple clients
milnivlek commented 3 weeks ago

@bai-yi-bai - Thanks for sharing your experience. I am also using Home Assistant to initiate playback on Snapcast. If you remove the credentials from the Snapcast config, then won't your Snapcast Spotify Connect source get unlinked from your Spotify account after being inactive for some time? How are you able to keep Snapcast in the list of Spotify Connect sources via Home Assistant?

rwjack commented 3 weeks ago

I think he meant like he removed those portions and made his peace that Spotify is trash and that we should all look into playing music locally and not through their garbage API

bai-yi-bai commented 3 weeks ago

@bai-yi-bai - Thanks for sharing your experience. I am also using Home Assistant to initiate playback on Snapcast. If you remove the credentials from the Snapcast config, then won't your Snapcast Spotify Connect source get unlinked from your Spotify account after being inactive for some time? How are you able to keep Snapcast in the list of Spotify Connect sources via Home Assistant?

The Home Assistant Spotify API uses the developer credentials (client ID/client secret) set up in the Spotify developer portal. I don't think it ever used username and password credentials. I simply had to "cycle" it to re-establish the link.

I think he meant like he removed those portions and made his peace that Spotify is trash and that we should all look into playing music locally and not through their garbage API

LOL - Yes, my first thought was to see if Snapcast supported any other streaming services, but for me the recommendation algorithm has been a great way to discover new music and new genres.

rwjack commented 3 weeks ago

Yes... The recommendation algorithm... It's the only thing keeping that ship afloat

fraintt commented 2 weeks ago

I can also confirm that in the last weeks my Spotify Password was reset due to suspicious activity and therefor I also was not able to login with librespot also with changed credentials.

3052 commented 1 week ago

Spotify Password Authentication Deprecated

its not. the current Spotify Android client definitely still support email/password, Ive been testing it all day. in fact my code from last month still works as is, if you add a user-agent

manuelkue commented 1 week ago

@3052

if you add a user-agent

Do you mean with Snapcast / librespot? Could you please elaborate, how to set a user-agent?

3052 commented 1 week ago

I have an implementation here if it helps

https://github.com/3052/platform/tree/v1.4.9/spotify

c13github-ir commented 1 week ago

I built an OS image based on Snapcast (just so I could give "whole-house audio" systems to non-technical people for birthdays, holidays, etc.). What worked for me was to use the librespot build from dtcooper's Raspotify (https://dtcooper.github.io/raspotify/). The OS image I built is Debian-based, so I:


Then zeroconf magic takes care of the rest: I sign in to Spotify on another device (Spotify client or web browser) and it sees  DESIRED_SPOTIFY_DEVICE_NAME as an available device for playback.
rwjack commented 1 week ago

Wait so zeroconf actually works? Why tf are we busting our nuts trying to configure credentials.json and whatnot as per: https://github.com/librespot-org/librespot/issues/1308#issuecomment-2294947853

milnivlek commented 1 week ago

In my case, it's helpful because I use my home autoomation to programmatically initiate playbacks on my Snapcast source, without using the Spotify app. Since ZeroConf logins expire after some period of inactivity (~10 min I think?), it's helpful to just permanently associate the Snapcast source with my Spotify account so that it never disappears from my list of Spotify Connect devices.

sadziu82 commented 1 week ago

I used librespot-auth to generate my credentials.json. Then I copied it into /var/cache/librespot/<STREAM_NAME>/credentials.json and restarted snapserver - it's working for a few days now without issues. I just had to remove username and password from stream definition.

fraintt commented 1 week ago

Wait so zeroconf actually works? Why tf are we busting our nuts trying to configure credentials.json and whatnot as per: librespot-org/librespot#1308 (comment)

Because I also want to:

If you only want to use spotify "locally" on the local LAN/Wifi, then you do not need to pass any credentials

c13github-ir commented 1 week ago

In my case, it's helpful because I use my home autoomation to programmatically initiate playbacks on my Snapcast source, without using the Spotify app. Since ZeroConf logins expire after some period of inactivity (~10 min I think?), it's helpful to just permanently associate the Snapcast source with my Spotify account so that it never disappears from my list of Spotify Connect devices.

Yeah, this only handles playback, not control. For control, there are a bunch of projects out there (I used to use https://gist.github.com/wandernauta/6800547) - but then you're back to having to deal with credentials again. Basically, exactly what @fraintt said.

Re: the ZeroConf login expiration, thanks - I wasn't aware of that. I haven't had any issues running for weeks at a time, but I also haven't needed to have Spotify reconnect to devices when I'm no longer on the same network as them.

rwjack commented 1 week ago

@fraintt oh riiight, I need that functionality as well, so good thing I got it working then.

fraintt commented 1 week ago

I used librespot-auth to generate my credentials.json. Then I copied it into /var/cache/librespot/<STREAM_NAME>/credentials.json and restarted snapserver - it's working for a few days now without issues. I just had to remove username and password from stream definition.

Hi, I did the same, I have credentials.json but for me it still does not work.. I do not see the Spotify device when not connected to the local LAN. I also do not see anything in the Logs. At start I saw that there were permissions issues accessing the Path, which I fixed by changing ownership. How does your stream link/path look like? Have you specified any cache?

Also, I´m using raspotify, as librespot seems to be abandoned (last release 2 years ago. (i know, raspotify is also not u2date but I had better experience with raspotify)