fix: only try to refresh access tokens if we have a refresh token or an expiry time (#594)
This commit is contained in:
parent
de62b1b087
commit
63d89b1a4e
1 changed files with 10 additions and 7 deletions
|
|
@ -612,13 +612,16 @@ impl AuthorizationManager {
|
|||
let credentials = stored.and_then(|s| s.token_response);
|
||||
|
||||
if let Some(creds) = credentials.as_ref() {
|
||||
let expires_in = creds.expires_in().unwrap_or(Duration::from_secs(0));
|
||||
if expires_in <= Duration::from_secs(0) {
|
||||
tracing::info!("Access token expired, refreshing.");
|
||||
// check token expiry if we have a refresh token or an expiry time
|
||||
if creds.refresh_token().is_some() || creds.expires_in().is_some() {
|
||||
let expires_in = creds.expires_in().unwrap_or(Duration::from_secs(0));
|
||||
if expires_in <= Duration::from_secs(0) {
|
||||
tracing::info!("Access token expired, refreshing.");
|
||||
|
||||
let new_creds = self.refresh_token().await?;
|
||||
tracing::info!("Refreshed access token.");
|
||||
return Ok(new_creds.access_token().secret().to_string());
|
||||
let new_creds = self.refresh_token().await?;
|
||||
tracing::info!("Refreshed access token.");
|
||||
return Ok(new_creds.access_token().secret().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(creds.access_token().secret().to_string())
|
||||
|
|
|
|||
Loading…
Reference in a new issue