MCPcopy Create free account
hub / github.com/Louisym/MiniCC / resolve_startup_auth_source

Function resolve_startup_auth_source

rust/crates/api/src/client.rs:385–420  ·  view source on GitHub ↗
(load_oauth_config: F)

Source from the content-addressed store, hash-verified

383}
384
385pub fn resolve_startup_auth_source<F>(load_oauth_config: F) -> Result<AuthSource, ApiError>
386where
387 F: FnOnce() -> Result<Option<OAuthConfig>, ApiError>,
388{
389 if let Some(api_key) = read_env_non_empty("ANTHROPIC_API_KEY")? {
390 return match read_env_non_empty("ANTHROPIC_AUTH_TOKEN")? {
391 Some(bearer_token) => Ok(AuthSource::ApiKeyAndBearer {
392 api_key,
393 bearer_token,
394 }),
395 None => Ok(AuthSource::ApiKey(api_key)),
396 };
397 }
398 if let Some(bearer_token) = read_env_non_empty("ANTHROPIC_AUTH_TOKEN")? {
399 return Ok(AuthSource::BearerToken(bearer_token));
400 }
401
402 let Some(token_set) = load_saved_oauth_token()? else {
403 return Err(ApiError::MissingApiKey);
404 };
405 if !oauth_token_is_expired(&token_set) {
406 return Ok(AuthSource::BearerToken(token_set.access_token));
407 }
408 if token_set.refresh_token.is_none() {
409 return Err(ApiError::ExpiredOAuthToken);
410 }
411
412 let Some(config) = load_oauth_config()? else {
413 return Err(ApiError::Auth(
414 "saved OAuth token is expired; runtime OAuth config is missing".to_string(),
415 ));
416 };
417 Ok(AuthSource::from(resolve_saved_oauth_token_set(
418 &config, token_set,
419 )?))
420}
421
422fn resolve_saved_oauth_token_set(
423 config: &OAuthConfig,

Calls 4

read_env_non_emptyFunction · 0.85
load_saved_oauth_tokenFunction · 0.85
oauth_token_is_expiredFunction · 0.85