Skip to content

Commit

Permalink
Fix auth token not being set properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigellute committed Sep 17, 2021
1 parent 89b3721 commit 5c0f57c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/auth_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl OAuthClient for AuthCodeSpotify {
&self.oauth
}

fn set_token(&mut self, token: Option<Token>) {
self.token = token;
}

/// Obtains a user access token given a code, as part of the OAuth
/// authentication. The access token will be saved internally.
async fn request_token(&mut self, code: &str) -> ClientResult<()> {
Expand Down
4 changes: 4 additions & 0 deletions src/auth_code_pkce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ impl OAuthClient for AuthCodePkceSpotify {
&self.oauth
}

fn set_token(&mut self, token: Option<Token>) {
self.token = token;
}

async fn request_token(&mut self, code: &str) -> ClientResult<()> {
// TODO
let mut data = Form::new();
Expand Down
7 changes: 5 additions & 2 deletions src/clients/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use url::Url;
pub trait OAuthClient: BaseClient {
fn get_oauth(&self) -> &OAuth;

fn set_token(&mut self, token: Option<Token>);

/// Obtains a user access token given a code, as part of the OAuth
/// authentication. The access token will be saved internally.
async fn request_token(&mut self, code: &str) -> ClientResult<()>;
Expand Down Expand Up @@ -97,8 +99,9 @@ pub trait OAuthClient: BaseClient {
#[maybe_async]
async fn prompt_for_token(&mut self, url: &str) -> ClientResult<()> {
match self.read_token_cache().await? {
Some(ref mut new_token) => {
self.get_token_mut().replace(new_token);
// TODO: shouldn't this also refresh the obtained token?
Some(new_token) => {
self.set_token(Some(new_token));
}
// Otherwise following the usual procedure to get the token.
None => {
Expand Down

0 comments on commit 5c0f57c

Please sign in to comment.