Refresh the access token for a specific provider.
(&self, provider_id: &str)
| 326 | |
| 327 | /// Refresh the access token for a specific provider. |
| 328 | pub async fn refresh(&self, provider_id: &str) -> Result<(), OAuthError> { |
| 329 | let provider = self |
| 330 | .providers |
| 331 | .get(provider_id) |
| 332 | .ok_or_else(|| OAuthError::ProviderNotFound(provider_id.to_string()))?; |
| 333 | |
| 334 | let refresh_token = { |
| 335 | let tokens = self.tokens.read().await; |
| 336 | tokens |
| 337 | .get(provider_id) |
| 338 | .and_then(|t| t.refresh_token.clone()) |
| 339 | .ok_or_else(|| { |
| 340 | OAuthError::RefreshFailed(format!( |
| 341 | "no refresh token for provider '{provider_id}'" |
| 342 | )) |
| 343 | })? |
| 344 | }; |
| 345 | |
| 346 | info!(provider = %provider_id, "Refreshing OAuth access token"); |
| 347 | let new_tokens = provider.refresh(&refresh_token).await?; |
| 348 | self.storage |
| 349 | .save(provider_id, &new_tokens) |
| 350 | .map_err(|e| OAuthError::StorageError(e.to_string()))?; |
| 351 | self.tokens |
| 352 | .write() |
| 353 | .await |
| 354 | .insert(provider_id.to_string(), new_tokens); |
| 355 | info!(provider = %provider_id, "OAuth token refreshed successfully"); |
| 356 | Ok(()) |
| 357 | } |
| 358 | |
| 359 | /// Store tokens after a successful login (called from onboard flow). |
| 360 | pub async fn store_tokens( |
no test coverage detected