Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Bad credentials" error when starting spotifyd #1293

Open
1 of 6 tasks
DavidHospital opened this issue Jul 29, 2024 · 58 comments
Open
1 of 6 tasks

"Bad credentials" error when starting spotifyd #1293

DavidHospital opened this issue Jul 29, 2024 · 58 comments
Labels
bug A functionality or parts of a program that do not work as intended

Comments

@DavidHospital
Copy link

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 #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
<!-- PLEASE PASTE YOUR LOGS BELOW THIS LINE WHEN REPORTING BUGS. Make sure to run spotifyd using the `--verbose` flag -->
<!-- They have to be betwenn the `/summary` and the `/details` HTML tags, and inside the backticks '`' -->  
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

  • dbus_mpris
  • dbus_keyring
  • alsa_backend
  • portaudio_backend
  • pulseaudio_backend
  • rodio_backend

Versions (please complete the following information):

  • OS: Ubuntu 22.04.4 LTS
  • Spotifyd: 0.3.5 (cargo)
  • cargo: 1.79.0
@DavidHospital DavidHospital added the bug A functionality or parts of a program that do not work as intended label Jul 29, 2024
@mghalix
Copy link

mghalix commented Jul 29, 2024

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

@robbertkauffman
Copy link

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
Copy link

timjrd commented Jul 29, 2024

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
Copy link
Member

eladyn commented Jul 29, 2024

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
Copy link

inkhey commented Jul 30, 2024

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
Copy link

dabalroman commented Jul 30, 2024

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
Copy link
Member

eladyn commented Jul 30, 2024

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
Copy link
Author

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
Copy link
Member

eladyn commented Jul 30, 2024

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

@bennylb
Copy link

bennylb commented Jul 31, 2024

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
Copy link

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
Copy link

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
Copy link

@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
Copy link

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

@mazarian
Copy link

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

@casualNavigator
Copy link

@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
Copy link

Semmu commented Aug 14, 2024

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
Copy link

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
Copy link

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

@whisperzer0
Copy link

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

user / password are still not working since yesterday.

@Semmu
Copy link

Semmu commented Aug 15, 2024

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
Copy link

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
Copy link

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
Copy link

jolo2486 commented Aug 16, 2024

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
Copy link

dspearson commented Aug 16, 2024

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
Copy link

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
Copy link

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
Copy link

@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
Copy link

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

@whisperzer0
Copy link

whisperzer0 commented Aug 18, 2024

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
Copy link

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
Copy link

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
Copy link

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
Copy link
Member

eladyn commented Aug 19, 2024

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
Copy link
Author

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
Copy link

Semmu commented Aug 19, 2024

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

@dabalroman
Copy link

dabalroman commented Aug 19, 2024

  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
Copy link

mghalix commented Aug 19, 2024

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
Copy link

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
Copy link

Moltey commented Aug 21, 2024

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
Copy link

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

@luke-barnett
Copy link

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
Copy link

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
Copy link

whisperzer0 commented Aug 25, 2024

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

#1293 (comment)

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

@Isaac-Leonard
Copy link

Isaac-Leonard commented Aug 26, 2024

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
Copy link

Bklyn97 commented Aug 26, 2024

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
Copy link

whisperzer0 commented Aug 26, 2024

@Isaac-Leonard
@Bklyn97
@Montero1905

You can generate a credentials.json file as instructed by this comment.
#1293 (comment)

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
Copy link

@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.

@Isaac-Leonard
Copy link

Okay, I got it to work, it only shows up in the spotify desk top app

@fgordilloz
Copy link

fgordilloz commented Aug 29, 2024

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

After creating the credentials file, leaving it where it should be (cache dir) and keeping the username value ​​in spotifyd.conf, everything worked again.

Thank you very much, @dspearson

@eladyn
Copy link
Member

eladyn commented Sep 5, 2024

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?

Oh, I'm sorry totally forgot about that. The latest release v0.3.5 accidentally disabled credential caching. It has been re-enabled on master, but has not made it to release yet. So this workaround only works on pre 0.3.5 or on the latest master.

@einalex
Copy link

einalex commented Sep 8, 2024

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

Setting the zeroconf_port to a higher number allowed this to work for me.

@Semmu
Copy link

Semmu commented Sep 10, 2024

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?

Oh, I'm sorry totally forgot about that. The latest release v0.3.5 accidentally disabled credential caching. It has been re-enabled on master, but has not made it to release yet. So this workaround only works on pre 0.3.5 or on the latest master.

ohh wow, this was the key for me, i downgraded to v0.3.4 and now the credentials caching works and finally i dont have to manually reauthenticate via zeroconf every time i restart the container! thanks!

@eladyn
Copy link
Member

eladyn commented Sep 12, 2024

Thanks for the confirmation. Maybe a new release would make sense, especially regarding some other issues.

@takase1121
Copy link

takase1121 commented Sep 16, 2024

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?

Oh, I'm sorry totally forgot about that. The latest release v0.3.5 accidentally disabled credential caching. It has been re-enabled on master, but has not made it to release yet. So this workaround only works on pre 0.3.5 or on the latest master.

ohh wow, this was the key for me, i downgraded to v0.3.4 and now the credentials caching works and finally i dont have to manually reauthenticate via zeroconf every time i restart the container! thanks!

I was able to avoid the downgrade by chmod 400 credentials.json. This is definitely a temporary fix but it will prevent spotifyd running as the user from ever removing the file.

@aurimarapsilva
Copy link

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 .

For now it works for me, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A functionality or parts of a program that do not work as intended
Projects
None yet
Development

No branches or pull requests