MCPcopy Create free account
hub / github.com/clawshell/clawshell / refresh

Method refresh

src/oauth/mod.rs:328–357  ·  view source on GitHub ↗

Refresh the access token for a specific provider.

(&self, provider_id: &str)

Source from the content-addressed store, hash-verified

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(

Callers 3

forward_oauth_requestFunction · 0.45
current_access_tokenMethod · 0.45
spawn_refresh_tasksMethod · 0.45

Calls 1

saveMethod · 0.80

Tested by

no test coverage detected