Skip to content

Commit

Permalink
Improve the robustness of the token update process
Browse files Browse the repository at this point in the history
  • Loading branch information
z-Wind committed Jul 25, 2024
1 parent 62db905 commit f638bb4
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,16 @@ impl TokenChecker {
}

if token.is_refresh_valid() {
let rsp = self
.authorizer
.access_token(&token.refresh)
.await
.map_err(|e| Error::Token(e.to_string()))?;
token.access.clone_from(rsp.access_token().secret());
token.access_expires_in = chrono::Utc::now()
.checked_add_signed(ACCESS_TOKEN_LIFETIME)
.expect("access_expires_in");

token.save(self.path.clone())?;
if let Ok(rsp) = self.authorizer.access_token(&token.refresh).await {
token.access.clone_from(rsp.access_token().secret());
token.access_expires_in = chrono::Utc::now()
.checked_add_signed(ACCESS_TOKEN_LIFETIME)
.expect("access_expires_in");

return Ok(());
token.save(self.path.clone())?;

return Ok(());
}
}

*token = self.authorizer.save(self.path.clone()).await?;
Expand Down

0 comments on commit f638bb4

Please sign in to comment.