Helper: persist a token response to the auth store.
(
&self,
token_result: &oauth2::StandardTokenResponse<EF, oauth2::basic::BasicTokenType>,
)
| 254 | |
| 255 | /// Helper: persist a token response to the auth store. |
| 256 | async fn save_token_result<EF: oauth2::ExtraTokenFields>( |
| 257 | &self, |
| 258 | token_result: &oauth2::StandardTokenResponse<EF, oauth2::basic::BasicTokenType>, |
| 259 | ) -> Result<(), OAuthError> { |
| 260 | let now_secs = std::time::SystemTime::now() |
| 261 | .duration_since(std::time::UNIX_EPOCH) |
| 262 | .unwrap_or_default() |
| 263 | .as_secs_f64(); |
| 264 | |
| 265 | let tokens = auth::OAuthTokens { |
| 266 | access_token: token_result.access_token().secret().clone(), |
| 267 | refresh_token: token_result.refresh_token().map(|t| t.secret().clone()), |
| 268 | expires_at: token_result |
| 269 | .expires_in() |
| 270 | .map(|d| now_secs + d.as_secs_f64()), |
| 271 | scope: token_result.scopes().map(|s| { |
| 272 | s.iter() |
| 273 | .map(|sc| sc.to_string()) |
| 274 | .collect::<Vec<_>>() |
| 275 | .join(" ") |
| 276 | }), |
| 277 | }; |
| 278 | |
| 279 | auth::update_tokens(&self.mcp_name, tokens, Some(&self.server_url)) |
| 280 | .await |
| 281 | .map_err(OAuthError::Storage)?; |
| 282 | |
| 283 | Ok(()) |
| 284 | } |
| 285 | /// Return a valid access token, refreshing if necessary. |
| 286 | /// |
| 287 | /// Returns `None` if no tokens are stored (the caller should initiate the |
no test coverage detected