[PR #263] [MERGED] Refresh fixes #355

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

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/263
Author: @marioortizmanero
Created: 10/10/2021
Status: Merged
Merged: 10/11/2021
Merged by: @ramsayleung

Base: ramsay_support_refresh_token_v2Head: refresh-fixes


📝 Commits (9)

📊 Changes

12 files changed (+178 additions, -161 deletions)

View changed files

📝 Cargo.toml (+5 -0)
examples/tasks.rs (+44 -0)
📝 examples/ureq/threading.rs (+3 -4)
📝 examples/with_auto_reauth.rs (+58 -48)
📝 rspotify-model/src/auth.rs (+5 -8)
📝 src/auth_code.rs (+1 -6)
📝 src/auth_code_pkce.rs (+2 -9)
📝 src/client_creds.rs (+2 -38)
📝 src/clients/base.rs (+43 -21)
📝 src/clients/oauth.rs (+1 -21)
📝 src/lib.rs (+1 -2)
📝 tests/test_oauth2.rs (+13 -4)

📄 Description

Description

Some fixes for #262:

  • Improved threading example
  • New threading example for async with tasks
  • Fix and tidy up the examples/with_auto_reauth.rs example
  • Moves auto_reauth and refresh_token to the trait, since we already have refetch_token available.
  • Avoids unbounded recursivity (stack overflow)
  • Simplifies everything a lot by only refreshing the token automatically when the request is being made, and not whenever it's accessed to. Thus, auto_reauth is only called once, and we can avoid having two token getters (one that refreshes and another that doesn't).
  • Token::is_expired now includes a margin of 10 seconds
  • Token::can_reauth was wrong: it checked if refresh_token was Some(), but that's not true in the case of client credentials.

Motivation and Context

See #262

Dependencies

None

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

You can run the new test with:

cargo run --example tasks --features=cli,env-file

🔄 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/263 **Author:** [@marioortizmanero](https://github.com/marioortizmanero) **Created:** 10/10/2021 **Status:** ✅ Merged **Merged:** 10/11/2021 **Merged by:** [@ramsayleung](https://github.com/ramsayleung) **Base:** `ramsay_support_refresh_token_v2` ← **Head:** `refresh-fixes` --- ### 📝 Commits (9) - [`b864aa9`](https://github.com/ramsayleung/rspotify/commit/b864aa9f27eb89310cebeee6efacab0ddffbf003) New test and improved threading one - [`d51824e`](https://github.com/ramsayleung/rspotify/commit/d51824e40c3b59988a03f32ce4d1577083687dfc) Fix stack overflow - [`a314b6e`](https://github.com/ramsayleung/rspotify/commit/a314b6e7582bb21a1222b16739a01ab763aefee5) Improve the with_auto_reauth example - [`d880302`](https://github.com/ramsayleung/rspotify/commit/d8803024ac4d4e5371ade60cc41f6397dad100a4) Finally fix the example! - [`7151603`](https://github.com/ramsayleung/rspotify/commit/71516037e4fec6c80c4306c59b5a762329e6a54f) Fix docs - [`8db2f8f`](https://github.com/ramsayleung/rspotify/commit/8db2f8f32ae512a2f332628b2d9714bf741b936a) Fix tests - [`ca6943a`](https://github.com/ramsayleung/rspotify/commit/ca6943a1e564e62b4ef4e3c6b4b24c370b5994e0) Move get_token to the trait - [`e96bc56`](https://github.com/ramsayleung/rspotify/commit/e96bc5616115c0df84240677abf153fc777d60f1) Fix expiring test - [`fb98bc0`](https://github.com/ramsayleung/rspotify/commit/fb98bc0bfb8fc9e089571348475347c0b5a895c5) Only reauth when performing a request ### 📊 Changes **12 files changed** (+178 additions, -161 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.toml` (+5 -0) ➕ `examples/tasks.rs` (+44 -0) 📝 `examples/ureq/threading.rs` (+3 -4) 📝 `examples/with_auto_reauth.rs` (+58 -48) 📝 `rspotify-model/src/auth.rs` (+5 -8) 📝 `src/auth_code.rs` (+1 -6) 📝 `src/auth_code_pkce.rs` (+2 -9) 📝 `src/client_creds.rs` (+2 -38) 📝 `src/clients/base.rs` (+43 -21) 📝 `src/clients/oauth.rs` (+1 -21) 📝 `src/lib.rs` (+1 -2) 📝 `tests/test_oauth2.rs` (+13 -4) </details> ### 📄 Description ## Description Some fixes for #262: * Improved threading example * New threading example for async with tasks * Fix and tidy up the `examples/with_auto_reauth.rs` example * Moves `auto_reauth` and `refresh_token` to the trait, since we already have `refetch_token` available. * Avoids unbounded recursivity (stack overflow) * Simplifies everything a lot by only refreshing the token automatically when the request is being made, and not whenever it's accessed to. Thus, `auto_reauth` is only called once, and we can avoid having two token getters (one that refreshes and another that doesn't). * `Token::is_expired` now includes a margin of 10 seconds * `Token::can_reauth` was wrong: it checked if `refresh_token` was `Some()`, but that's not true in the case of client credentials. ## Motivation and Context See #262 ## Dependencies None ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? You can run the new test with: ``` cargo run --example tasks --features=cli,env-file ``` --- <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:24 +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#355
No description provided.