dtcooper / raspotify

A Spotify Connect client that mostly Just Works™
https://dtcooper.github.io/raspotify
MIT License
4.68k stars 217 forks source link

Enable support for OAuth #675

Open 1ukastesar opened 2 months ago

1ukastesar commented 2 months ago

Raspotify is just a package

Due Diligence

What can we do to make Raspotify more awesome?

As of https://github.com/librespot-org/librespot/issues/1308 and subsequent PR https://github.com/librespot-org/librespot/pull/1309, Spotify has apparently disabled password auth altogether and forces OAuth for everyone. Please add an option to authenticate with OAuth through librespot. Upstream librespot already supports OAuth with -j option, somehow I can't figure out which cache dir to use to get it working with Raspotify after successful auth.

TagorePde commented 2 months ago

Same issue i get :

Password authentication no longer supported, use OAuth

any way to solve this? Regards.

krzyssiek commented 2 months ago

i also have this problem.

sanjibm commented 2 months ago

Same problem, got the auth token via librespot, but not sure where to put it so that Raspotify can see it

kimtore commented 2 months ago

I suspect this can be solved by not using a dynamic user through systemd. This way, you will be able to write to raspotify's directory. I won't be able to test this until next week, however. Perhaps you could try it out.

Change /lib/systemd/system/raspotify.service from

[Service]
DynamicUser=yes

to

[Service]
DynamicUser=no

Then run systemctl daemon-reload && systemctl restart raspotify.

sanjibm commented 2 months ago

Thanks @kimtore, that worked perfectly!

For anyone landing here, below is a summary of the steps I followed to get this working on a Raspberry Pi 4 running Bullseye with Librespot v0.4.2. Note that although I had to compile librespot from source to run it and get the authentication token, I did not need to actually install it again overwriting the release version.

  1. Stopped the raspotify service with systemctl stop raspotify after noticing errors on the librespot logs: Connection failed: Login failed with reason: Bad credentials

  2. Cloned the tip of the librespot repository to get the fix (no new release available at the time of writing, v0.4.2 was last release) and built it locally on the Raspberry Pi following instructions here: https://github.com/librespot-org/librespot/blob/master/COMPILING.md

Might need to install Rust if you didn't have it already. Make sure you select the right backend, in my case had to specify alsa using: cargo build --no-default-features --features "alsa-backend"

  1. Followed the advice in this comment to authenticate using OAuth: https://github.com/librespot-org/librespot/pull/1309#issuecomment-2348563401

After running the librespot --cache <YOUR_CONFIGURATION_PATH> -j command on the Pi, I noted the listener port number

  1. Then copied the full output URL on to a laptop browser, which had port-forwarding setup via ssh to point back to the Raspberry Pi IP address and port.

  2. That then authenticated to Spotify on the laptop browser (needed to enter Spotify username/password), which sent the authentication response back to the Raspberry Pi (via port-forwarding), writing the authentication token to the path specified when running librespot with the -j option

  3. Changed /lib/systemd/system/raspotify.service as advised above to specify

    [Service]
    DynamicUser=no

    Then run systemctl daemon-reload && systemctl restart raspotify.

After this, noticed below new lines in the librespot logs: Found pre-existing private CacheDirectory= directory /var/cache/private/raspotify, migrating to /var/cache/raspotify. Apparently, service previously had DynamicUser= turned on, and has now turned it off.

Was also still seeing the Bad Credentials failure message too at this point, as it was still using username/password

  1. The authentication token was still in the folder specified and the token file is called credentials.json. I copied that now to the cache folder mentioned in the logs: cp credentials.json /var/cache/raspotify/

  2. Updated the raspotify config file sudo vi /etc/raspotify/conf to comment out below items to enable 0Auth instead of username/password

    #LIBRESPOT_DISABLE_CREDENTIAL_CACHE=
    #LIBRESPOT_DISABLE_DISCOVERY=
    #LIBRESPOT_USERNAME="mysecretusername"
    #LIBRESPOT_PASSWORD="mysecretpassword"
  3. Restarted raspotify with systemctl restart raspotify and everything worked, clean librespot logs no more errors

kimtore commented 2 months ago

Great, thanks for detailing the steps!

Here are my thoughts.

github-actions[bot] commented 2 months ago

More info has been requested. The issue will be closed shortly if it's not provided.

ACalleM commented 2 weeks ago

Just wanted to comment that you dont need port forwarding for the OAuth flow. You can copy the callback URL returned by spotify (with a 127.0.0.1 address) and use curl to invoke it from the raspberrypi where you executed "librespot --cache -j"