Skip to content

Commit 79d03f7

Browse files
committed
fix: only try to refresh access tokens if we have a refresh token or an expiry time
1 parent eeacd13 commit 79d03f7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/rmcp/src/transport/auth.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,16 @@ impl AuthorizationManager {
612612
let credentials = stored.and_then(|s| s.token_response);
613613

614614
if let Some(creds) = credentials.as_ref() {
615-
let expires_in = creds.expires_in().unwrap_or(Duration::from_secs(0));
616-
if expires_in <= Duration::from_secs(0) {
617-
tracing::info!("Access token expired, refreshing.");
618-
619-
let new_creds = self.refresh_token().await?;
620-
tracing::info!("Refreshed access token.");
621-
return Ok(new_creds.access_token().secret().to_string());
615+
// check token expiry if we have a refresh token or an expiry time
616+
if creds.refresh_token().is_some() || creds.expires_in().is_some() {
617+
let expires_in = creds.expires_in().unwrap_or(Duration::from_secs(0));
618+
if expires_in <= Duration::from_secs(0) {
619+
tracing::info!("Access token expired, refreshing.");
620+
621+
let new_creds = self.refresh_token().await?;
622+
tracing::info!("Refreshed access token.");
623+
return Ok(new_creds.access_token().secret().to_string());
624+
}
622625
}
623626

624627
Ok(creds.access_token().secret().to_string())

0 commit comments

Comments
 (0)