Skip to content

Commit

Permalink
auth_code_pkce: add from_token_with_config() constructor
Browse files Browse the repository at this point in the history
This is required to be able to refresh an expired token from the cache
as we need the client ID to refresh the token.

Fix #511
  • Loading branch information
gdesmott committed Dec 29, 2024
1 parent bd35dbc commit a9c14b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

**New features**
- ([#496](https://github.com/ramsayleung/rspotify/pull/497)) Add support for searching multiple types
- ([#512](https://github.com/ramsayleung/rspotify/pull/512)) Add `AuthCodePkceSpotify::from_token_with_config()`


## 0.13.3 (2024.08.24)
Expand Down
18 changes: 18 additions & 0 deletions src/auth_code_pkce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ impl AuthCodePkceSpotify {
}
}

/// Build a new [`AuthCodePkceSpotify`] from an already generated token and
/// config. Use this to be able to refresh a token.
#[must_use]
pub fn from_token_with_config(
token: Token,
creds: Credentials,
oauth: OAuth,
config: Config,
) -> Self {
Self {
token: Arc::new(Mutex::new(Some(token))),
creds,
oauth,
config,
..Default::default()
}
}

/// Generate the verifier code and the challenge code.
fn generate_codes(verifier_bytes: usize) -> (String, String) {
log::info!("Generating PKCE codes");
Expand Down

0 comments on commit a9c14b5

Please sign in to comment.