pub struct AuthStorage { /* private fields */ }Expand description
Auth storage wrapper with file locking.
Implementations§
Source§impl AuthStorage
impl AuthStorage
Sourcepub async fn load_async(path: PathBuf) -> Result<Self>
pub async fn load_async(path: PathBuf) -> Result<Self>
Load auth.json asynchronously (creates empty if missing).
Sourcepub async fn save_async(&self) -> Result<()>
pub async fn save_async(&self) -> Result<()>
Persist auth.json asynchronously.
Sourcepub fn get(&self, provider: &str) -> Option<&AuthCredential>
pub fn get(&self, provider: &str) -> Option<&AuthCredential>
Get raw credential.
Sourcepub fn set(&mut self, provider: impl Into<String>, credential: AuthCredential)
pub fn set(&mut self, provider: impl Into<String>, credential: AuthCredential)
Insert or replace a credential for a provider.
Sourcepub fn api_key(&self, provider: &str) -> Option<String>
pub fn api_key(&self, provider: &str) -> Option<String>
Get API key for provider from auth.json.
For ApiKey and BearerToken variants the key/token is returned directly.
For OAuth the access token is returned only when not expired.
For AwsCredentials the access key ID is returned (callers needing the full
credential set should use [get] instead).
For ServiceKey this returns None because a token exchange is required first.
Sourcepub fn provider_names(&self) -> Vec<String>
pub fn provider_names(&self) -> Vec<String>
Return the names of all providers that have stored credentials.
Sourcepub fn credential_status(&self, provider: &str) -> CredentialStatus
pub fn credential_status(&self, provider: &str) -> CredentialStatus
Return stored credential status for a provider, including canonical alias fallback.
Sourcepub fn remove_provider_aliases(&mut self, provider: &str) -> bool
pub fn remove_provider_aliases(&mut self, provider: &str) -> bool
Remove stored credentials for provider and any known aliases/canonical IDs.
Matching is case-insensitive to clean up legacy mixed-case auth entries.
Sourcepub fn has_stored_credential(&self, provider: &str) -> bool
pub fn has_stored_credential(&self, provider: &str) -> bool
Returns true when auth.json contains a credential for provider
(including canonical alias fallback).
Sourcepub fn external_setup_source(&self, provider: &str) -> Option<&'static str>
pub fn external_setup_source(&self, provider: &str) -> Option<&'static str>
Return a human-readable source label when credentials can be auto-detected from other locally-installed coding CLIs.
Sourcepub fn resolve_api_key(
&self,
provider: &str,
override_key: Option<&str>,
) -> Option<String>
pub fn resolve_api_key( &self, provider: &str, override_key: Option<&str>, ) -> Option<String>
Resolve API key with precedence.
Sourcepub async fn refresh_expired_oauth_tokens(&mut self) -> Result<()>
pub async fn refresh_expired_oauth_tokens(&mut self) -> Result<()>
Refresh any expired OAuth tokens that this binary knows how to refresh.
This keeps startup behavior predictable: models that rely on OAuth credentials remain available after restart without requiring the user to re-login.
Sourcepub async fn refresh_expired_oauth_tokens_with_client(
&mut self,
client: &Client,
) -> Result<()>
pub async fn refresh_expired_oauth_tokens_with_client( &mut self, client: &Client, ) -> Result<()>
Refresh any expired OAuth tokens using the provided HTTP client.
This is primarily intended for tests and deterministic harnesses (e.g. VCR playback), but is also useful for callers that want to supply a custom HTTP implementation.
Sourcepub async fn refresh_expired_extension_oauth_tokens(
&mut self,
client: &Client,
extension_configs: &HashMap<String, OAuthConfig>,
) -> Result<()>
pub async fn refresh_expired_extension_oauth_tokens( &mut self, client: &Client, extension_configs: &HashMap<String, OAuthConfig>, ) -> Result<()>
Refresh expired OAuth tokens for extension-registered providers.
extension_configs maps provider ID to its OAuthConfig.
Providers already handled by refresh_expired_oauth_tokens_with_client (e.g. “anthropic”)
are skipped.
Sourcepub fn prune_stale_credentials(&mut self, max_age_ms: i64) -> Vec<String>
pub fn prune_stale_credentials(&mut self, max_age_ms: i64) -> Vec<String>
Remove OAuth credentials that expired more than max_age_ms ago and
whose refresh token is no longer usable (no stored token_url/client_id
and no matching extension config).
Returns the list of pruned provider IDs.
Trait Implementations§
Source§impl Clone for AuthStorage
impl Clone for AuthStorage
Source§fn clone(&self) -> AuthStorage
fn clone(&self) -> AuthStorage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AuthStorage
impl RefUnwindSafe for AuthStorage
impl Send for AuthStorage
impl Sync for AuthStorage
impl Unpin for AuthStorage
impl UnsafeUnpin for AuthStorage
impl UnwindSafe for AuthStorage
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more