devgianlu / go-librespot

Yet another open source Spotify client, written in Go.
GNU General Public License v3.0
133 stars 17 forks source link

Question about spotify_token #64

Closed hecht0r closed 1 month ago

hecht0r commented 2 months ago

Hi,

while using go-librespot with zeroconf works like a charm i want to use stored credentials. With zeroconf i have to select go-librespot as device manually in my spotify client. After that it works perfectly.

I tried to get my access_token via

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

and put it in my config.yml like this:

credentials:
  type: spotify_token
  spotify_token:
    username: xxxx@gmail.com     
    access_token:  %he acces_token i got%

After starting go-libresport i get error FATA[0001] failed running with username and spotify token error="failed authenticating accesspoint with username and spotify token: failed authenticating: failed login: BadCredentials"

What am I doing wrong? Thank you for any help

devgianlu commented 2 months ago

You need to request a token with the correct scopes, they are listed here: https://github.com/devgianlu/go-librespot/blob/b9bc8c87f1b63cdffb6977ecd879d11db3373a78/session/session.go#L101-L126

If that feats you, the interactive login mode is also available which will handle the OAuth2 flow for you.

hecht0r commented 2 months ago

Interactive unfortunately doesn't work. FATA[0000] unknown credentials: interactive

config.yml looks like this:

device_name: go-librespot
credentials:
  type: interactive

i am using the latest prebuild executable go-librespot_linux_arm64.tar.gz

devgianlu commented 2 months ago

This feature has not been released yet, to test it you need to compile yourself or wait for the next release.

ChristianRamseier commented 2 months ago

Looking forward to see the interactive feature released. It would be nice if the redirect url will be configurable (i.e. a hostname instead of 127.0.0.1).

devgianlu commented 2 months ago

It would be nice if the redirect url will be configurable (i.e. a hostname instead of 127.0.0.1).

We are using the client ID used by Spotify in its official client, so I am guessing they have locked it down to 127.0.0.1.

ChristianRamseier commented 2 months ago

It would be nice if the redirect url will be configurable (i.e. a hostname instead of 127.0.0.1).

We are using the client ID used by Spotify in its official client, so I am guessing they have locked it down to 127.0.0.1.

Hmm, ok. If they indeed locked it down, it means the browser with the login window needs to run on the same host as librespot?

devgianlu commented 2 months ago

It would be nice if the redirect url will be configurable (i.e. a hostname instead of 127.0.0.1).

We are using the client ID used by Spotify in its official client, so I am guessing they have locked it down to 127.0.0.1.

Hmm, ok. If they indeed locked it down, it means the browser with the login window needs to run on the same host as librespot?

You can copy the login URL go-librespot gives you into your browser, complete the signin and when it redirects you to 127.0.0.1 you copy that and do curl "..." on the device where go-librespot runs. It is annoying, but you need to do it only once.