pub struct AuthManager { /* private fields */ }Implementations§
Source§impl AuthManager
impl AuthManager
pub fn in_config_dir(config_dir: &Path) -> Result<Self>
pub fn login( &self, profile_name: &str, provider: &str, token: &str, activate: bool, ) -> Result<()>
pub fn paste_token( &self, profile_name: &str, provider: &str, token: &str, activate: bool, ) -> Result<()>
pub fn paste_redirect( &self, profile_name: &str, provider: &str, redirect_or_code: &str, activate: bool, ) -> Result<()>
pub fn store_oauth_tokens( &self, profile_name: &str, provider: &str, access_token: &str, refresh_token: Option<&str>, expires_in_secs: Option<u64>, activate: bool, ) -> Result<()>
pub fn save_pending_oauth_login( &self, pending: &PendingOAuthLogin, ) -> Result<()>
pub fn load_pending_oauth_login(&self) -> Result<Option<PendingOAuthLogin>>
pub fn clear_pending_oauth_login(&self) -> Result<()>
pub fn refresh( &self, profile_name: &str, access_token: &str, refresh_token: Option<&str>, expires_in_secs: Option<u64>, activate: bool, ) -> Result<()>
pub fn refresh_for_provider( &self, provider: &str, profile_name: Option<&str>, ) -> Result<Option<RefreshResult>>
pub fn logout(&self, profile_name: Option<&str>) -> Result<bool>
pub fn remove_profile(&self, provider: &str, profile_name: &str) -> Result<bool>
pub fn use_profile(&self, profile_name: &str) -> Result<()>
pub fn list_profiles(&self) -> Result<Vec<AuthProfileSummary>>
Sourcepub fn active_token_for_provider(
&self,
provider: &str,
) -> Result<Option<String>>
pub fn active_token_for_provider( &self, provider: &str, ) -> Result<Option<String>>
Return the stored token for the given provider, preferring the active profile, then a profile named “default”, then any matching profile.
Sourcepub fn token_for_profile(
&self,
profile_name: &str,
) -> Result<Option<(String, String)>>
pub fn token_for_profile( &self, profile_name: &str, ) -> Result<Option<(String, String)>>
Look up a profile by name (regardless of provider kind).
Returns (provider_kind, token) if found.
Sourcepub fn resolve_credential(
&self,
profile_name: Option<&str>,
current_provider: &str,
) -> Result<Option<ResolvedCredential>>
pub fn resolve_credential( &self, profile_name: Option<&str>, current_provider: &str, ) -> Result<Option<ResolvedCredential>>
Resolve credentials from stored auth profiles.
Resolution order:
- If
profile_nameisSome, look up that profile by name. - Active profile matching
current_provider. - Any active profile (provider may differ — caller should update config).
Returns None if no usable credential is found.
pub fn status(&self) -> Result<AuthStatus>
Sourcepub fn token_health(&self) -> Result<Vec<ProfileHealth>>
pub fn token_health(&self) -> Result<Vec<ProfileHealth>>
Return the health of all profiles (for auth status display).
Sourcepub fn ensure_valid_token(&self, provider: &str) -> Result<Option<String>>
pub fn ensure_valid_token(&self, provider: &str) -> Result<Option<String>>
Check that the active profile for provider has a valid token.
If the token is expired and has a refresh token, attempts a local
refresh (extends expiry). Returns the token if valid/refreshed, or
an error if the token is expired and cannot be refreshed.
This is designed to be called by the runtime before each provider call.
Source§impl AuthManager
impl AuthManager
Sourcepub fn migrate_if_needed(&self) -> Result<bool>
pub fn migrate_if_needed(&self) -> Result<bool>
Migrate auth state from v1 to v2 format if needed.
v1 → v2: adds refresh_token and token_expires_at_epoch_secs fields
to profiles (handled by serde #[serde(default)]). The migration
just bumps the version marker.