kokarare1212 / librespot-python

Open Source Spotify Client
http://librespot-python.rtfd.io
Apache License 2.0
231 stars 43 forks source link

[REQUEST] Create session using user's token #195

Closed staniel359 closed 1 year ago

staniel359 commented 1 year ago

Is your feature request related to a problem? Please describe.

I'm running your library on a server for multiple users. Right now I'm using my own Spotify credentials for all users. When a user decides to connect their account, instead of storing their credentials I'd like to store their access token (for security reasons) and use it to create each user's session.

Describe the solution you'd like

Session.Builder().token(<USER_TOKEN>)

kokarare1212 commented 1 year ago

Perhaps this should work.

session = Session.Builder() \
    .user_pass("<email address>", "<password>") \
    .create()

stored_credentials = session.stored()
session2 = Session.Builder().stored(stored_credentials).create()
staniel359 commented 1 year ago

@kokarare1212 But what if I don't want to use any users' emails or passwords? Is it possible to login user via their token?

kokarare1212 commented 1 year ago

It is necessary for the first login, but from the next time onward, such a thing can be done by obtaining something like a token in session.stored and passing it as an argument to Session.Builder.stored, as in the above code.

staniel359 commented 1 year ago

@kokarare1212 Okay, thanks.