Spotifyd / spotifyd

A spotify daemon
https://spotifyd.rs
GNU General Public License v3.0
9.79k stars 447 forks source link

"Bad credentials" error when starting spotifyd #1293

Open DavidHospital opened 1 month ago

DavidHospital commented 1 month ago

Description I've been using spotifyd for a few years now without issue. Just this morning when trying to connect, I got the following error:

failed to connect to spotify: Login failed with reason: Bad credentials

I am able to login just fine on all my other devices, it's only using spotifyd where I have this issue. I have also tried restarting my PC, and using my email as username instead of the username string, as suggested by https://github.com/Spotifyd/spotifyd/issues/1269, but neither have worked.

To Reproduce

  1. start with spotifyd --verbose --no-daemon

Expected behavior spotifyd should authenticate with spotify

Logs

Click to show logs ``` Loading config from "/home/dhospital/.config/spotifyd/spotifyd.conf" CliConfig { config_path: None, no_daemon: true, verbose: true, pid: None, shared_config: SharedConfigValues { username: Some("taken out for privacy"), username_cmd: None, password: Some("taken out for privacy"), password_cmd: None, use_keyring: false, use_mpris: None, dbus_type: None, on_song_change_hook: None, cache_path: None, no-audio-cache: false, backend: Some(Alsa), volume_controller: None, device: None, control: None, mixer: None, device_name: Some("WorkUbuntu"), bitrate: Some(Bitrate160), audio_format: None, initial_volume: Some("50"), volume_normalisation: false, normalisation_pregain: Some(-10.0), zeroconf_port: None, proxy: None, device_type: Some(Computer), autoplay: false, max_cache_size: None } } Found user shell: Some("/bin/bash") No proxy specified registering event source with poller: token=Token(2147483649), interests=READABLE Using software volume controller. registering event source with poller: token=Token(0), interests=READABLE | WRITABLE signal: Want signal found waiting giver, notifying poll_want: taker wants! signal: Want signal: Want Ignoring blacklisted access point ap-gue1.spotify.com:4070 Ignoring blacklisted access point ap-gue1.spotify.com:443 Ignoring blacklisted access point ap-gue1.spotify.com:80 Connecting to AP "ap-gae2.spotify.com:443" deregistering event source from poller signal: Closed registering event source with poller: token=Token(16777216), interests=READABLE | WRITABLE deregistering event source from poller failed to connect to spotify: Login failed with reason: Bad credentials ```

Compilation flags

Versions (please complete the following information):

mghalix commented 1 month ago

Got exactly the same bug just today (been working for so long now) image

robbertkauffman commented 1 month ago

Same here. It was working fine for months and stopped working this morning. Using configured username & password and have disabled zeroconf.

I believe it's an issue with librespot as I get the same error with Raspotify.

timjrd commented 1 month ago

Hi! 🙂 Same thing, but I run librespot directly like that:

#!/usr/bin/env bash
librespot \
    --username "$(head -n 1 ~/.config/librespot/auth)" \
    --password "$(tail -n 1 ~/.config/librespot/auth)" \
    --backend alsa \
    --format F32 \
    --mixer softvol \
    --volume-ctrl fixed \
    --initial-volume 100 \
    --bitrate 320

... then I get:

[2024-07-29T14:52:58Z ERROR librespot] Connection failed: Login failed with reason: Bad credentials

Nothing interesting with the verbose flag.

eladyn commented 1 month ago

Indeed something seems to have changed on the Spotify side, since I found already several reports (on several projects) which report the exact same error (most reports have been published recently). It started happening for me too, the issue persists when using the newest librespot dev version, so probably something that needs to be fixed upstream.

Anyway, for now what still should be working (from my tests) is discovery, so until this is fixed it might be a viable option for you?


Issues in other projects:

inkhey commented 1 month ago

Hello all, same problem here too.

Anyway, for now what still should be working (from my tests) is discovery, so until this is fixed it might be a viable option for you?

What do you mean by "discovery" ?

dabalroman commented 1 month ago

What do you mean by "discovery" ?

Indeed, it still works with discovery. To enable it, all of these values in config should be commented out.

#username=
#password=

See here: https://docs.spotifyd.rs/config/File.html#alternatives-to-storing-your-password-in-the-config-file

Your device will be visible in spotify app as a player (probably requires same network for devices to work).

eladyn commented 1 month ago

Yeah, thanks for the clarification. For spotifyd, you need to comment out the username and password line in the config to make it go into discovery mode.

DavidHospital commented 1 month ago

See here: https://docs.spotifyd.rs/config/File.html#alternatives-to-storing-your-password-in-the-config-file

Your device will be visible in spotify app as a player (probably requires same network for devices to work).

I can't get this to work, I've commented out username and password, as well as cache_path and cache_directory. When I launch spotifyd, it says Zeroconf server listening on 0.0.0.0:39127, but none of my devices can see it on the network. Am I missing something?

eladyn commented 1 month ago

It might be some firewall issue? Make sure you expose the ports 5353 UDP and the one that the logs say via TCP.

bennylb commented 1 month ago

See here: https://docs.spotifyd.rs/config/File.html#alternatives-to-storing-your-password-in-the-config-file Your device will be visible in spotify app as a player (probably requires same network for devices to work).

I can't get this to work, I've commented out username and password, as well as cache_path and cache_directory. When I launch spotifyd, it says Zeroconf server listening on 0.0.0.0:39127, but none of my devices can see it on the network. Am I missing something?

I had to use the official Spotify client to first authenticate with zeroconf and then spotifyd became visible to other devices on the network. Just opening the official app was enough.

dspearson commented 1 month ago

FYI, as I mentioned on the librespot issue, SpConnectionLoginZeroConf is a mandatory implementation feature for Spotify Connect devices and the documentation for hardware implementers states that SpConnectionLoginPassword was to only be used for testing purposes -- it has in fact been removed from the eSDK and therefore I assume should never be used.

The blob obtained via ZeroConf authentication flow is not tied to devices on the same network currently, and so for those wishing to reduce effort or network/mDNS config issues, simply running spotifyd on the same machine as a running official client for initial device registration, and then copying the credentials obtained to a remote machine where spotifyd is to be deployed, should work just fine. At least I tested it with librespot with no issues.

casualNavigator commented 1 month ago

FYI, as I mentioned on the librespot issue, SpConnectionLoginZeroConf is a mandatory implementation feature for Spotify Connect devices and the documentation for hardware implementers states that SpConnectionLoginPassword was to only be used for testing purposes -- it has in fact been removed from the eSDK and therefore I assume should never be used.

The blob obtained via ZeroConf authentication flow is not tied to devices on the same network currently, and so for those wishing to reduce effort or network/mDNS config issues, simply running spotifyd on the same machine as a running official client for initial device registration, and then copying the credentials obtained to a remote machine where spotifyd is to be deployed, should work just fine. At least I tested it with librespot with no issues.

@dspearson thanks for this, this explained why spotifyd suddenly stoped working today because of Bad Credential errors (?)

I cannot find the blob ~/.cache/spotifyd nor ~/.config/spotifyd, is it stored here?

dspearson commented 1 month ago

@casualNavigator unfortunately I'm not a spotifyd user but taking a brief look at the code it uses librespot's crates directly so maybe try find on ~, looking for credentials.json? You're typically looking for a key called auth_data.

casio1983 commented 1 month ago

@casualNavigator in my case the credentials.json are stored in the cache_path location specified in config file ~/.config/spotifyd/spotifyd.conf

mazarian commented 1 month ago

Same issue on my end but I'm using raspotify.

casualNavigator commented 1 month ago

@dspearson and @casio1983 Thanks, found a credentials.json file for spotify_player cli (which uses librespot) in ~/.config/spotify-player/credentials.json, and indeed contained auth_data but I wasn't able to use it, as I tried resetting my Spotify password trying to troubleshoot this issue. Thanks for pointing out to the right direction.

I've tried to generate the auth_data manually using instructions here https://developer.spotify.com/documentation/web-api/tutorials/getting-started:

curl -X POST "https://accounts.spotify.com/api/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=client_credentials&client_id=my-client-id&client_secret=my-client-secret"

And updated the auth_data value in the credentials.json file, unfortunately that didn't work.

Semmu commented 4 weeks ago

same issue here, and also i got an email from Spotify forcing me to change my password because they detected some "suspicious activity".

(i really hope they are not killing spotifyd and other third-party clients...)

dabalroman commented 4 weeks ago

same issue here, and also i got an email from Spotify forcing me to change my password because they detected some "suspicious activity".

(i really hope they are not killing spotifyd and other third-party clients...)

Same here. Just migrated from raspotify to spotifyd and got that email. At least zeroconf works better in spotifyd.

elliotclee commented 4 weeks ago

Discovery mode worked for me after I commented 'username' and 'password' out of the config file.

whisperzer0 commented 4 weeks ago

Discovery works, but then plays via my phone not desktop via spotify-qt.

user / password are still not working since yesterday.

Semmu commented 4 weeks ago

is there a workaround to authenticate with some saved credentials/token automatically? could spotifyd write some tokens to some file after a successful zeroconf authentication, which it could read at startup?

the reason im asking is because my spotifyd disconnects after being idle for hours ( bugreported here #903 ) for which my workaround is to monitor/poll my active devices via the API and restart the spotifyd container whenever the API thinks its gone. ( commented here )

but since the username+password auth has been turned off on Spotify's side, whenever my container is restarted it wont belong to my account, so it will essentially get in a "bootloop" and i will need to do the zeroconf authentication each time (which is inconvenient). it would be nice if spotifyd persisted the tokens in some file which could be re-used until they are expired.

dabalroman commented 4 weeks ago

There is a file called credentials.json in cache directory. There is some kind of key inside alongside username. Check if that directory is not wiped out on docker down action. It works for at least couple of hours and it's visible in spotify app after device restart. I compiled Spotifyd from source, it's running a system service under Ubuntu.

dspearson commented 4 weeks ago

You can use the cached discovery credentials for a long time. I've used mine for weeks now. Like previously mentioned, just make sure they're not deleted in your workflow.

jolo2486 commented 3 weeks ago

Same or similar problem here with spotifyd 0.3.5 on Ubuntu 22.04.4:

$ spotifyd --no-daemon --verbose --username redacted --password redacted --backend pulseaudio --debug-credentials

No config file specified. Running with default values
CliConfig { config_path: None, no_daemon: true, verbose: true, pid: None, shared_config: SharedConfigValues { username: Some(redacted), username_cmd: None, password: Some(redacted), password_cmd: None, use_keyring: false, use_mpris: None, dbus_type: None, on_song_change_hook: None, cache_path: None, no-audio-cache: false, backend: Some(PulseAudio), volume_controller: None, device: None, control: None, mixer: None, device_name: None, bitrate: None, audio_format: None, initial_volume: None, volume_normalisation: false, normalisation_pregain: None, zeroconf_port: None, proxy: None, device_type: None, autoplay: false, max_cache_size: None } }
Found user shell: Some("/bin/bash")
No proxy specified
Using software volume controller.
Ignoring blacklisted access point ap-gew4.spotify.com:4070
Ignoring blacklisted access point ap-gew4.spotify.com:443
Ignoring blacklisted access point ap-gew4.spotify.com:80
Ignoring blacklisted access point ap-gue1.spotify.com:443
Failed to resolve Access Point: Unable to resolve any viable access points.
Using fallback "ap.spotify.com:443"
Connecting to AP "ap.spotify.com:443"
failed to connect to spotify: Login failed with reason: Bad credentials

I also tried discovery mode by commenting out username and password in spotifyd.conf, but it seems to be stuck. I don't think I have a credentials.json anywhere because I've not used spotifyd on this computer before, only at work, where it worked fine (haven't tried these past weeks):

Additional question. Do I need a credentials.json for discovery to work and can I create one myself?

$ spotifyd --no-daemon --verbose

Loading config from "/home/mrredacted/.config/spotifyd/spotifyd.conf"
CliConfig { config_path: None, no_daemon: true, verbose: true, pid: None, shared_config: SharedConfigValues { username: None, username_cmd: None, password: None, password_cmd: None, use_keyring: false, use_mpris: None, dbus_type: None, on_song_change_hook: Some("command_to_run_on_playback_events"), cache_path: Some("cache_directory"), no-audio-cache: true, backend: Some(Alsa), volume_controller: Some(Alsa), device: Some("alsa_audio_device"), control: Some("alsa_audio_device"), mixer: Some("PCM"), device_name: Some("redacted"), bitrate: Some(Bitrate160), audio_format: Some(S16), initial_volume: Some("90"), volume_normalisation: true, normalisation_pregain: Some(-10.0), zeroconf_port: Some(1234), proxy: None, device_type: Some(Speaker), autoplay: true, max_cache_size: Some(1000000000) } }
Found user shell: Some("/bin/bash")
No username specified. Checking username_cmd
No username_cmd specified
No password specified. Checking password_cmd
No password_cmd specified
No proxy specified
Using alsa volume controller.
no usable credentials found, enabling discovery
Using device id 'a35baa7bd3fe13630f66325b0b734cfc0c7cdeec'
Zeroconf server listening on 0.0.0.0:1234
found interface Interface { name: "eno1", addr: V4(Ifv4Addr { ip: 192.168.1.177, netmask: 255.255.255.0, broadcast: Some(192.168.1.255) }) }
sending packet to 224.0.0.251:5353
found interface Interface { name: "eno1", addr: V4(Ifv4Addr { ip: 192.168.1.177, netmask: 255.255.255.0, broadcast: Some(192.168.1.255) }) }
sending packet to [ff02::fb]:5353
received packet from 192.168.1.177:5353
received packet from 192.168.1.177:5353 with no query
received packet from 192.168.1.177:5353
received packet from 192.168.1.177:5353 with no query
received packet from [fe80::aeca:908d:27:dd69%2]:5353
received packet from [fe80::aeca:908d:27:dd69%2]:5353 with no query
received packet from [fe80::aeca:908d:27:dd69%2]:5353
received question: IN _ipps._tcp.local
received question: IN _ipp._tcp.local
received packet from 192.168.1.177:5353
received question: IN _ipps._tcp.local
received question: IN _ipp._tcp.local
_

and it just stays there (+10 min), nothing happens, and I have to interrupt the process.

I've n-ple (n>>2) checked the username and password as well as tried both with conf and CLI (-u, -p) with and without " and/or '. I also changed/updated my spotify password and it has no "problematic" characters such as spaces or ".

dspearson commented 3 weeks ago

For those that seem to have issues creating the credentials.json file, I have created the following: https://github.com/dspearson/librespot-auth

Build with cargo build --release (requires rust compiler/toolkit, see https://rustup.rs/). Example usage:

❯ ./target/release/librespot-auth --name "Example Speaker"
Open Spotify and select output device: Example Speaker
Credentials saved: credentials.json
Mike-de-bike commented 3 weeks ago

For those that seem to have issues creating the credentials.json file, I have created the following: https://github.com/dspearson/librespot-auth

Build with cargo build --release (requires rust compiler/toolkit, see https://rustup.rs/). Example usage:

❯ ./target/release/librespot-auth --name "Example Speaker"
Open Spotify and select output device: Example Speaker
Credentials saved: credentials.json

is that using of a manually created credentials.json a workaround to get spotifyd in zeroconf mode running? Has someone positive results in using it?

MarekLew commented 3 weeks ago

For those that seem to have issues creating the credentials.json file, I have created the following: https://github.com/dspearson/librespot-auth

Build with cargo build --release (requires rust compiler/toolkit, see https://rustup.rs/). Example usage:

❯ ./target/release/librespot-auth --name "Example Speaker"
Open Spotify and select output device: Example Speaker
Credentials saved: credentials.json

It works. After confirming authorization for "Example Speaker" in the spotify client, copy the generated credentials.json file to the cache_patch location saved in the ~/.config/spotifyd/spotifyd.conf file, e.g. ~/.cache/spotifyd .

casualNavigator commented 3 weeks ago

@dspearson Worked, flawlessly! Built it in Rust to too, what an absolute Chadman!

@Mike-de-bike Confirmed working, was able to use spotifyd and spotify-player again.

trames57 commented 3 weeks ago

Just wanted to add here #1285 that if you have 2 IP address on your interface you may have issues with discovery.

dspearson commented 3 weeks ago

Good catch. I'm going to try and fix that in my utility right now, because it stems from the default librespot behaviour. Unexpected for sure.

Edit: Okay, after three hours of mucking around, I think it's possibly a bug in either mdns, systemd, or I'm not understanding this enough to guess. Am giving up for now but the credentials one receives from zeroconf are long-lasting at least, if it's really a big problem I'd suggest raising it with librespot, because they added a command line option that I also adopted but had the same issue, so I'm not sure it actually got fixed.

Mike-de-bike commented 3 weeks ago

@dspearson Worked, flawlessly! Built it in Rust to too, what an absolute Chadman!

@Mike-de-bike Confirmed working, was able to use spotifyd and spotify-player again.

Confirming merely, that it works using the version 0.1 of libresport auth! spotfiyd runs in docker container on aarch64 Ubuntu20.04. Credentials file is written magically in cache dir. Great commmendation for @dspearson !

whisperzer0 commented 3 weeks ago

For those that seem to have issues creating the credentials.json file, I have created the following: https://github.com/dspearson/librespot-auth

Build with cargo build --release (requires rust compiler/toolkit, see https://rustup.rs/). Example usage:

❯ ./target/release/librespot-auth --name "Example Speaker"
Open Spotify and select output device: Example Speaker
Credentials saved: credentials.json

Many thanks for coding that. Really appreciated, kudos.

I couldn't get spotifyd with FreeBSD recognising credentials.json, but is working with librespot which too works with spotify-qt. Normality resolved.

I'll take a shot of tequila in your honor.

MattGesicki commented 3 weeks ago

Hi guys, It happened to me on RPi and Raspotify. When I reinstalled latest Raspotify, service is running. Once configuring username and password in /etc/rapotify/config I got the same error about bad credentials. Can you please advise if above step with librespot-auth would do the trick? Do I need to install Spotify desktop version, log in and find credentails.json?

dabalroman commented 3 weeks ago

Hi guys, It happened to me on RPi and Raspotify. When I reinstalled latest Raspotify, service is running. Once configuring username and password in /etc/rapotify/config I got the same error about bad credentials. Can you please advise if above step with librespot-auth would do the trick? Do I need to install Spotify desktop version, log in and find credentails.json?

For raspotify you must enable zeroconf first, there is a key for that in config file. This mode should create credentials itself, the librespot-auth is a fallback when zeroconf does not work as expected.

Look for these in /etc/raspotify/conf, all should be commented out:

# LIBRESPOT_DISABLE_CREDENTIAL_CACHE=
# LIBRESPOT_DISABLE_DISCOVERY=
#LIBRESPOT_USERNAME=""
#LIBRESPOT_PASSWORD=""
IdoEsports commented 3 weeks ago

MacOS Sonoma 14.4 and spotifyd version 0.3.5.

Hey,

I used librespot-auth to generate the credentials.json and made sure to place it in the right cache directory. But for some reason, "no usable credentials found" like this:

~/.config/spotifyd ➜ spotifyd --no-daemon

Loading config from "/Users/abhijeetsurakanti/.config/spotifyd/spotifyd.conf"
No password specified. Checking password_cmd
No password_cmd specified
No proxy specified
Using software volume controller.
no usable credentials found, enabling discovery
error sending packet Os { code: 65, kind: HostUnreachable, message: "No route to host" }

I've confirmed that the credentials.json file is being read by including syntax erros which were caught like this:

~/.config/spotifyd ➜ spotifyd --no-daemon

Loading config from "/Users/abhijeetsurakanti/.config/spotifyd/spotifyd.conf"
No password specified. Checking password_cmd
No password_cmd specified
No proxy specified
Using software volume controller.
Error reading credentials from cache: expected `,` or `}` at line 5 column 2
no usable credentials found, enabling discovery
error sending packet Os { code: 65, kind: HostUnreachable, message: "No route to host" }

As for the: error sending packet Os { code: 65, kind: HostUnreachable, message: "No route to host" } I believe it is related to #1026 which hasn't given me much trouble in the past because it only shows up in discovery mode.

This made me wonder if the credentials were valid so I copied the credentials.json file over to the cache folder of spotify-player. I was facing the same "Bad credentials" error for spotify-player as well and the new credentials.json file actually ended up solving the error and I'm able to use it like regular.

I appreciate any help and also great work building this thread so far.

eladyn commented 3 weeks ago

Thanks to everyone who is helping to work around this issue!

For a spotifyd-only solution, you can do the following:

  1. Set cache_path to a writable directory (e.g. /home/user/.cache/spotifyd).
  2. Start spotifyd in discovery mode (by commenting all the username, username_cmd, ... options). You should see the line no usable credentials found, enabling discovery in your logs.
  3. Connect with any of the official clients to spotifyd (which has to be on the same network).
  4. Stop spotifyd. Make sure that in the cache directory that you set before, there is now a file called credentials.json.
  5. To make spotifyd use that file, we have to provide it with the correct username which can be found in credentials.json. (Set the username option to the username that can be found in credentials.json.)
  6. Start spotifyd again, it should now authenticate successfully (and not enter discovery mode!)

Note: Instead of step 5, you can also use the following very clean solution: Set the option username_cmd = "jq -r .username /yourcachedirectory/credentials.json". This will automatically retrieve the correct username from credentials.json so you can just clear the cache to connect to someone else's account.

DavidHospital commented 3 weeks ago

Thanks to everyone who is helping to work around this issue!

For a spotifyd-only solution, you can do the following:

1. Set `cache_path` to a writable directory (e.g. `/home/user/.cache/spotifyd`).

2. Start `spotifyd` in discovery mode (by commenting all the `username`, `username_cmd`, ... options). You should see the line `no usable credentials found, enabling discovery` in your logs.

3. Connect with any of the official clients to `spotifyd` (which has to be on the same network).

4. Stop `spotifyd`. Make sure that in the cache directory that you set before, there is now a file called `credentials.json`.

5. To make `spotifyd` use that file, we have to provide it with the correct username which can be found in `credentials.json`. (Set the `username` option to the username that can be found in `credentials.json`.)

6. Start `spotifyd` again, it should now authenticate successfully (and not enter discovery mode!)

Note: Instead of step 5, you can also use the following very clean solution: Set the option username_cmd = "jq -r .username /yourcachedirectory/credentials.json". This will automatically retrieve the correct username from credentials.json so you can just clear the cache to connect to someone else's account.

After step 4, I don't have a credentials.json in my cache directory, other files are being created there though, so the cache location is working. Any idea why that wouldn't be created?

Semmu commented 3 weeks ago

Same here, no credentials.json gets created after enabling the cache and authenticating via zeroconf 😕

dabalroman commented 3 weeks ago
  1. To make spotifyd use that file, we have to provide it with the correct username which can be found in credentials.json. (Set the username option to the username that can be found in credentials.json.)

Brilliant sugestion! Now the spotifyd works on last credentials.json for long time. I've noticed daemon switched to zeroconf due to missing username, and then had a problem with cache_directory path.. Mine spotify.service now looks like this:

# /etc/systemd/system/spotifyd.service
[Unit]
Description=A spotify playing daemon
Documentation=https://github.com/Spotifyd/spotifyd
Wants=sound.target
After=sound.target
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/home/<user>/spotifyd/target/release/spotifyd --no-daemon --config-path /home/<user>/.config/spotifyd/spotifyd.conf --cache-path /home/<user>/spotifyd/target/release/cache_directory --username <user>
Restart=always
RestartSec=12

[Install]
WantedBy=default.target

sudo systemctl daemon-reload and sudo systemctl restart spotifyd.service, then everything works just fine!

It is also worth to check the Spotify for developers / get available devices command. It will print all devices that are currently available for your account, so debugging is easier.

mghalix commented 3 weeks ago

Thanks to everyone who is helping to work around this issue!

For a spotifyd-only solution, you can do the following:

1. Set `cache_path` to a writable directory (e.g. `/home/user/.cache/spotifyd`).

2. Start `spotifyd` in discovery mode (by commenting all the `username`, `username_cmd`, ... options). You should see the line `no usable credentials found, enabling discovery` in your logs.

3. Connect with any of the official clients to `spotifyd` (which has to be on the same network).

4. Stop `spotifyd`. Make sure that in the cache directory that you set before, there is now a file called `credentials.json`.

5. To make `spotifyd` use that file, we have to provide it with the correct username which can be found in `credentials.json`. (Set the `username` option to the username that can be found in `credentials.json`.)

6. Start `spotifyd` again, it should now authenticate successfully (and not enter discovery mode!)

Note: Instead of step 5, you can also use the following very clean solution: Set the option username_cmd = "jq -r .username /yourcachedirectory/credentials.json". This will automatically retrieve the correct username from credentials.json so you can just clear the cache to connect to someone else's account.

This solved it for me, thanks!

MattGesicki commented 3 weeks ago

For raspotify you must enable zeroconf first, there is a key for that in config file. This mode should create credentials itself, the librespot-auth is a fallback when zeroconf does not work as expected.

Look for these in /etc/raspotify/conf, all should be commented out:

# LIBRESPOT_DISABLE_CREDENTIAL_CACHE=
# LIBRESPOT_DISABLE_DISCOVERY=
#LIBRESPOT_USERNAME=""
#LIBRESPOT_PASSWORD=""

That worked without any stuff with credentials.json, thanks!

Moltey commented 3 weeks ago

Thanks to everyone who is helping to work around this issue!

For a spotifyd-only solution, you can do the following:

1. Set `cache_path` to a writable directory (e.g. `/home/user/.cache/spotifyd`).

2. Start `spotifyd` in discovery mode (by commenting all the `username`, `username_cmd`, ... options). You should see the line `no usable credentials found, enabling discovery` in your logs.

3. Connect with any of the official clients to `spotifyd` (which has to be on the same network).

4. Stop `spotifyd`. Make sure that in the cache directory that you set before, there is now a file called `credentials.json`.

5. To make `spotifyd` use that file, we have to provide it with the correct username which can be found in `credentials.json`. (Set the `username` option to the username that can be found in `credentials.json`.)

6. Start `spotifyd` again, it should now authenticate successfully (and not enter discovery mode!)

Note: Instead of step 5, you can also use the following very clean solution: Set the option username_cmd = "jq -r .username /yourcachedirectory/credentials.json". This will automatically retrieve the correct username from credentials.json so you can just clear the cache to connect to someone else's account.

From one day to another, spotifyd stopped working for me with plain text credentials. You advice helped me. Thank you so much!

For those who also are working in a container that does not have 'jq' available, you may want to go the 'grep' way in 'spotifyd.conf':

[global]
zeroconf_port = 33797
cache_path = "/var/yourcachedirectory"
username_cmd = "grep -oP '(?<=\"username\":\")[^\"]*' /var/yourcachedirectory/credentials.json"
no_audio_cache = true
Rockandrolljunkie commented 2 weeks ago

Man, you just saved my life. Thank you so much! Much safer option too...

luke-barnett commented 2 weeks ago

After transitioning and capturing a working credentials.json file, my Spotify account had it's password rotated again by Spotify after detecting "suspicious activity".

I'm assuming that this may have just been bad timing (I forgot to disable the service and so it would have been trying to connect constantly), but before I jump through the hoops again, I'm guessing that no one else is experiencing this and after cleanly transitioning to a credentials.json file it keeps working (at least for a while until the token eventually expires?).

Montero1905 commented 2 weeks ago

Thanks to everyone who is helping to work around this issue!

For a spotifyd-only solution, you can do the following:

  1. Set cache_path to a writable directory (e.g. /home/user/.cache/spotifyd).
  2. Start spotifyd in discovery mode (by commenting all the username, username_cmd, ... options). You should see the line no usable credentials found, enabling discovery in your logs.
  3. Connect with any of the official clients to spotifyd (which has to be on the same network).
  4. Stop spotifyd. Make sure that in the cache directory that you set before, there is now a file called credentials.json.
  5. To make spotifyd use that file, we have to provide it with the correct username which can be found in credentials.json. (Set the username option to the username that can be found in credentials.json.)
  6. Start spotifyd again, it should now authenticate successfully (and not enter discovery mode!)

Note: Instead of step 5, you can also use the following very clean solution: Set the option username_cmd = "jq -r .username /yourcachedirectory/credentials.json". This will automatically retrieve the correct username from credentials.json so you can just clear the cache to connect to someone else's account.

There are is no 'credentials.json' file in the cache directory after stopping spotifyd. Is there another way to get the credentials.json file? I'm working on MacOS.

whisperzer0 commented 2 weeks ago

You can generate a credentials.json file as instructed by this comment.

https://github.com/Spotifyd/spotifyd/issues/1293#issuecomment-2293136285

https://github.com/dspearson/librespot-auth

Isaac-Leonard commented 2 weeks ago

Trying to run in discovery mode with the username and password_cmd fields commented out in my config seems to run but also gives me this error: sending packet to [ff02::fb]:5353 error sending packet Os { code: 65, kind: HostUnreachable, message: "No route to host" }

Which seems to be related to ipv6, this error is mentioned in an older issue but it was concluded that it should only be an issue on ipv6 only networks, which I'm not on but Spotifyd isn't showing up on my local network however so I'm not sure how to generate a fresh credentials.json file. If I open play.spotify.com then the webplayer shows up on my local network too so it's not a network issue.

Bklyn97 commented 2 weeks ago

I'm experiencing the same "Bad credentials" issue when starting spotifyd on Arch Linux. I’ve double-checked my username and password, and they are correct. Here's what I’ve tried so far:

Used both my Spotify username and email address as the username.
Tried entering credentials directly in the command line and in the spotifyd.conf file.
Removed the cache and config files, then retried with fresh setup.
Attempted running in discovery mode by commenting out the username and password fields in the config file.

Despite all this, I continue to receive the "Login failed with reason: Bad credentials" error.

whisperzer0 commented 2 weeks ago

@Isaac-Leonard @Bklyn97 @Montero1905

You can generate a credentials.json file as instructed by this comment. https://github.com/Spotifyd/spotifyd/issues/1293#issuecomment-2293136285

For those that seem to have issues creating the credentials.json file, I have created the following: https://github.com/dspearson/librespot-auth

Build with cargo build --release (requires rust compiler/toolkit, see https://rustup.rs/). Example usage:

❯ ./target/release/librespot-auth --name "Example Speaker"
Open Spotify and select output device: Example Speaker
Credentials saved: credentials.json

and then:

Thanks to everyone who is helping to work around this issue!

For a spotifyd-only solution, you can do the following:

1. Set `cache_path` to a writable directory (e.g. `/home/user/.cache/spotifyd`).

2. Start `spotifyd` in discovery mode (by commenting all the `username`, `username_cmd`, ... options). You should see the line `no usable credentials found, enabling discovery` in your logs.

3. Connect with any of the official clients to `spotifyd` (which has to be on the same network).

4. Stop `spotifyd`. Make sure that in the cache directory that you set before, there is now a file called `credentials.json`.

5. To make `spotifyd` use that file, we have to provide it with the correct username which can be found in `credentials.json`. (Set the `username` option to the username that can be found in `credentials.json`.)

6. Start `spotifyd` again, it should now authenticate successfully (and not enter discovery mode!)

Note: Instead of step 5, you can also use the following very clean solution: Set the option username_cmd = "jq -r .username /yourcachedirectory/credentials.json". This will automatically retrieve the correct username from credentials.json so you can just clear the cache to connect to someone else's account.

Isaac-Leonard commented 2 weeks ago

@SomeoneSomewhereHow I tried running the code at https://github.com/dspearson/librespot-auth but the device still doesn't show up in the webplayer or on my phone as available to connect to. I suspect it may be related to my wifi, I can either try connect over my universities wifi which does some funky stuff with their ip addresses and so the server may not be broadcasting. I've also tried connecting with my phone hotspot however and stil no luck.