[PR #1309] [MERGED] Credentials with access token (oauth) #1333

Closed
opened 2026-02-27 20:02:02 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/1309
Author: @kingosticks
Created: 8/6/2024
Status: Merged
Merged: 9/13/2024
Merged by: @roderickvd

Base: devHead: credentials_with_access_token


📝 Commits (10+)

  • 7a45614 core: Create credentials from access token
  • 4956da9 core: Credentials.username is optional.
  • eeec818 core: store auth data within session
  • ee7ba28 oauth: obtain Spotify access token via OAuth2
  • 60fae8f bin: New --token arg for using Spotify access token
  • fe4d36b oauth: break-out code parsing
  • 65a2526 Updated token example
  • 70e2e5f oauth: Update crate documentation
  • 2354d77 ouath: error handling, pass scopes as param, redirect_port is Option
  • e5f4e68 oauth: Return type

📊 Changes

17 files changed (+629 additions, -88 deletions)

View changed files

📝 CHANGELOG.md (+3 -0)
📝 Cargo.toml (+4 -0)
📝 core/Cargo.toml (+4 -0)
📝 core/src/authentication.rs (+15 -7)
📝 core/src/connection/mod.rs (+8 -5)
📝 core/src/error.rs (+21 -0)
📝 core/src/session.rs (+61 -15)
📝 examples/get_token.rs (+24 -13)
📝 examples/play.rs (+4 -4)
📝 examples/play_connect.rs (+4 -4)
📝 examples/playlist_tracks.rs (+4 -4)
oauth/Cargo.toml (+18 -0)
oauth/examples/oauth.rs (+32 -0)
oauth/src/lib.rs (+287 -0)
📝 publish.sh (+1 -1)
📝 src/lib.rs (+1 -0)
📝 src/main.rs (+138 -35)

📄 Description

I don't know if this oauth stuff really belongs in core, it doesn't feel quite right there so I added a new module. That new module could be useful standalone so it makes sense. If someone wants to take this and do something else that is fine by me.

This also leaves the token stuff a bit messy. We now provide two ways to get an access token:

  1. session.token_provider().get_token("your,scopes") using keymaster (Mercury)
  2. session.spclient().auth_token() using login5 (HTTP)

Both methods work (for session auth and playback) when you authenticate your session using a password or stored credentials. However, method 1 doesn't work when you authenticate your session using a spotify token (obtained using either method).

I think we want to get rid of this annoying pitfall. We could:
a) Get rid of method 1 altogether
b) Method 1 use method 2 under the hood
c) Change session authentication so when stored-creds are not used, it auths to obtain them and then re-auths using them.

Fixes #1308


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/1309 **Author:** [@kingosticks](https://github.com/kingosticks) **Created:** 8/6/2024 **Status:** ✅ Merged **Merged:** 9/13/2024 **Merged by:** [@roderickvd](https://github.com/roderickvd) **Base:** `dev` ← **Head:** `credentials_with_access_token` --- ### 📝 Commits (10+) - [`7a45614`](https://github.com/librespot-org/librespot/commit/7a45614ac477e8f409b68363f825726fcdda23c8) core: Create credentials from access token - [`4956da9`](https://github.com/librespot-org/librespot/commit/4956da9b8477a16cbcc8626e860baf5b2085d04f) core: Credentials.username is optional. - [`eeec818`](https://github.com/librespot-org/librespot/commit/eeec818d8345f900bee5bf211ee0f80195cfa788) core: store auth data within session - [`ee7ba28`](https://github.com/librespot-org/librespot/commit/ee7ba28e8d86e6b1c3ec45c9ecd1a04626f9b066) oauth: obtain Spotify access token via OAuth2 - [`60fae8f`](https://github.com/librespot-org/librespot/commit/60fae8fc7b08f09ff29e0b4aa20000c7cd673117) bin: New --token arg for using Spotify access token - [`fe4d36b`](https://github.com/librespot-org/librespot/commit/fe4d36bfb003ee9bdf9f86fafd03bce760e73da7) oauth: break-out code parsing - [`65a2526`](https://github.com/librespot-org/librespot/commit/65a252627f95f6ecf2b4c532b6afd773c477f52c) Updated token example - [`70e2e5f`](https://github.com/librespot-org/librespot/commit/70e2e5ffb1b6bf95304977eabcce91824e069aa8) oauth: Update crate documentation - [`2354d77`](https://github.com/librespot-org/librespot/commit/2354d77f8ee67f7157868b4f06d7fa2bca70e55e) ouath: error handling, pass scopes as param, redirect_port is Option - [`e5f4e68`](https://github.com/librespot-org/librespot/commit/e5f4e68e31d7a2a58f66bc1b86ff43de4d558a76) oauth: Return type ### 📊 Changes **17 files changed** (+629 additions, -88 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+3 -0) 📝 `Cargo.toml` (+4 -0) 📝 `core/Cargo.toml` (+4 -0) 📝 `core/src/authentication.rs` (+15 -7) 📝 `core/src/connection/mod.rs` (+8 -5) 📝 `core/src/error.rs` (+21 -0) 📝 `core/src/session.rs` (+61 -15) 📝 `examples/get_token.rs` (+24 -13) 📝 `examples/play.rs` (+4 -4) 📝 `examples/play_connect.rs` (+4 -4) 📝 `examples/playlist_tracks.rs` (+4 -4) ➕ `oauth/Cargo.toml` (+18 -0) ➕ `oauth/examples/oauth.rs` (+32 -0) ➕ `oauth/src/lib.rs` (+287 -0) 📝 `publish.sh` (+1 -1) 📝 `src/lib.rs` (+1 -0) 📝 `src/main.rs` (+138 -35) </details> ### 📄 Description I don't know if this oauth stuff really belongs in core, it doesn't feel quite right there so I added a new module. That new module could be useful standalone so it makes sense. If someone wants to take this and do something else that is fine by me. This also leaves the token stuff a bit messy. We now provide two ways to get an access token: 1. `session.token_provider().get_token("your,scopes")` using keymaster (Mercury) 2. `session.spclient().auth_token()` using login5 (HTTP) Both methods work (for session auth and playback) when you authenticate your session using a password or stored credentials. However, method 1 doesn't work when you authenticate your session using a spotify token (obtained using either method). I think we want to get rid of this annoying pitfall. We could: a) Get rid of method 1 altogether b) Method 1 use method 2 under the hood c) Change session authentication so when stored-creds are not used, it auths to obtain them and then re-auths using them. Fixes #1308 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:02:02 +03:00
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#1333
No description provided.