[PR #254] [MERGED] Fix oauth set token and fix unauthorized playback control #346

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

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/254
Author: @Rigellute
Created: 9/20/2021
Status: Merged
Merged: 9/20/2021
Merged by: @marioortizmanero

Base: masterHead: master


📝 Commits (4)

  • 9ff89c4 Fix auth token not being set properly
  • 09f5da4 Fix unauthorized playback control
  • 4bb3906 Revert "Fix auth token not being set properly"
  • 5527736 Change get_token_mut to return mutable reference to Option

📊 Changes

5 files changed (+11 additions, -10 deletions)

View changed files

📝 src/auth_code.rs (+2 -2)
📝 src/auth_code_pkce.rs (+2 -2)
📝 src/client_creds.rs (+2 -2)
📝 src/clients/base.rs (+1 -1)
📝 src/clients/oauth.rs (+4 -3)

📄 Description

Description

This PR fixes two issues:

  1. The prompt_for_token oauth flow was not loading the token after reading from the cache.
  2. All calls to start_context_playback resulted in "request unauthorized"

Motivation and Context

Regarding the first issue: Looks like the previous code was expecting the String.replace() method to mutate the original string, but replace creates a new string. I've added a new method to explicitly set the token. Unless there's a more consitent way?

For the second issue, the start_context_playback method was using the .put method and passing None for the headers, hence why all requests were unauthorized. I switched this to use endpoint_put, which appears to simply abstract the headers placement?

Dependencies

None.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Please also list any relevant details for your test configuration

For the token cache issue, you can reproduce on master by

  1. setting the auth config token_cached: true
  2. run prompt_for_token the first time to get the token (all requests are auth'ned)
  3. restart the program to load the token from the cache
  4. all requests are not auth'ned

For the not authorized playback control issue:

  1. Get the auth token and device id and a playback context uri
  2. Make the request and see the error

🔄 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/ramsayleung/rspotify/pull/254 **Author:** [@Rigellute](https://github.com/Rigellute) **Created:** 9/20/2021 **Status:** ✅ Merged **Merged:** 9/20/2021 **Merged by:** [@marioortizmanero](https://github.com/marioortizmanero) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (4) - [`9ff89c4`](https://github.com/ramsayleung/rspotify/commit/9ff89c41404b5281474da3532de1aef3f18fd8db) Fix auth token not being set properly - [`09f5da4`](https://github.com/ramsayleung/rspotify/commit/09f5da4c199d70b15280efcd10e216831541dd2a) Fix unauthorized playback control - [`4bb3906`](https://github.com/ramsayleung/rspotify/commit/4bb3906a83d3cd09e038d12c7c56d34d925e004b) Revert "Fix auth token not being set properly" - [`5527736`](https://github.com/ramsayleung/rspotify/commit/5527736de93524d98d7684307ae1b5a6271116cd) Change `get_token_mut` to return mutable reference to Option ### 📊 Changes **5 files changed** (+11 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/auth_code.rs` (+2 -2) 📝 `src/auth_code_pkce.rs` (+2 -2) 📝 `src/client_creds.rs` (+2 -2) 📝 `src/clients/base.rs` (+1 -1) 📝 `src/clients/oauth.rs` (+4 -3) </details> ### 📄 Description ## Description This PR fixes two issues: 1. The `prompt_for_token` oauth flow was not loading the token after reading from the cache. 2. All calls to `start_context_playback` resulted in "request unauthorized" ## Motivation and Context Regarding the first issue: Looks like the previous code was expecting the `String.replace()` method to mutate the original string, but `replace` [creates a new string](https://doc.rust-lang.org/std/string/struct.String.html#method.replace). I've added a new method to explicitly set the token. Unless there's a more consitent way? For the second issue, the `start_context_playback` method was using the `.put` method and passing `None` for the headers, hence why all requests were unauthorized. I switched this to use `endpoint_put`, which appears to simply abstract the headers placement? ## Dependencies None. ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration For the token cache issue, you can reproduce on master by 1. setting the auth config `token_cached: true` 2. run prompt_for_token the first time to get the token (all requests are auth'ned) 3. restart the program to load the token from the cache 4. all requests are not auth'ned For the not authorized playback control issue: 1. Get the auth token and device id and a playback context uri 2. Make the request and see the error --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:21 +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/rspotify#346
No description provided.