[GH-ISSUE #242] Can I use a token from spotify web API to create a librespot session? #165

Closed
opened 2026-02-27 19:29:10 +03:00 by kerem · 5 comments
Owner

Originally created by @paulo-raca on GitHub (Aug 6, 2018).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/242

Hello,
I'm using the Spotify Web API to crawl artists, albuns, etc, etc, and librespot to playback the tracks.

Right now I have to perform the login twice:

Is it possible to reuse the tokens from the web API or something, so that I don't need to login twice?

Thank you!

Originally created by @paulo-raca on GitHub (Aug 6, 2018). Original GitHub issue: https://github.com/librespot-org/librespot/issues/242 Hello, I'm using the Spotify Web API to crawl artists, albuns, etc, etc, and librespot to playback the tracks. Right now I have to perform the login twice: - One for the web APIs, using the [Authorization Code Flow](https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow) - One for Librespot, using username/password Is it possible to reuse the tokens from the web API or something, so that I don't need to login twice? Thank you!
kerem 2026-02-27 19:29:10 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@michaelherger commented on GitHub (Aug 6, 2018):

I went the other way around: I'm using librespot to get the token, which I then use to access the web API. It's much simpler, as I didn't have to implement the auth flow. Alas, it's not available from the default librespot application. I implemented it in my "spotty" helper application, which is based on librespot's main.rs and is using the librespot library. See https://github.com/michaelherger/spotty/blob/master/src/main.rs#L452

<!-- gh-comment-id:410737041 --> @michaelherger commented on GitHub (Aug 6, 2018): I went the other way around: I'm using librespot to get the token, which I then use to access the web API. It's much simpler, as I didn't have to implement the auth flow. Alas, it's not available from the default librespot application. I implemented it in my ["spotty"](https://github.com/michaelherger/spotty) helper application, which is based on librespot's `main.rs` and is using the librespot library. See https://github.com/michaelherger/spotty/blob/master/src/main.rs#L452
Author
Owner

@ashthespy commented on GitHub (Oct 2, 2018):

@paulo-raca you actually can do this by setting the auth_type to AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN and passing a username and a token.

<!-- gh-comment-id:426356102 --> @ashthespy commented on GitHub (Oct 2, 2018): @paulo-raca you actually can do this by setting the `auth_type` to [`AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN`](https://github.com/librespot-org/librespot/blob/master/protocol/proto/authentication.proto#L25) and passing a username and a token.
Author
Owner

@kingosticks commented on GitHub (Oct 2, 2018):

I guess you'll also need to make sure the token you pass has the the streaming scope.

FYI @adamcik

<!-- gh-comment-id:426363290 --> @kingosticks commented on GitHub (Oct 2, 2018): I guess you'll also need to make sure the token you pass has the the [streaming](https://developer.spotify.com/documentation/general/guides/scopes/#streaming) scope. FYI @adamcik
Author
Owner

@paulo-raca commented on GitHub (Oct 2, 2018):

Sounds good, thank you!
In this case, the username is the id field I get from https://api.spotify.com/v1/me ?

<!-- gh-comment-id:426369071 --> @paulo-raca commented on GitHub (Oct 2, 2018): Sounds good, thank you! In this case, the username is the `id` field I get from https://api.spotify.com/v1/me ?
Author
Owner

@ashthespy commented on GitHub (Oct 2, 2018):

I can dig up an implementation from long ago - but username is just your canonical username.

Just read the WebAPI docs and yes, it is the same id.

<!-- gh-comment-id:426373941 --> @ashthespy commented on GitHub (Oct 2, 2018): I can dig up an implementation from long ago - but username is just your canonical username. Just read the [WebAPI docs](https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids) and yes, it is the same id.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#165
No description provided.