Skip to main content

AuthStore

Struct AuthStore 

Source
pub struct AuthStore {
    pub stored: HashMap<String, StoredCredential>,
    /* private fields */
}
Expand description

Manages API keys and OAuth credentials.

Fields§

§stored: HashMap<String, StoredCredential>

Implementations§

Source§

impl AuthStore

Source

pub fn new(path: PathBuf) -> Self

Source

pub fn load(path: &Path) -> Result<Self>

Load stored credentials from disk.

Source

pub fn set_runtime_key(&mut self, provider: &str, key: String)

Set a runtime override (not persisted). Empty or whitespace-only values are treated as absent.

Source

pub fn has_credentials(&self, provider: &str) -> bool

Check whether credentials are usable for a provider without producing an error. Returns true if a runtime key, readable stored credential, or env var is available.

Source

pub fn resolve(&self, provider: &str) -> Result<ApiKey>

Resolution order: runtime override -> stored -> env var -> error.

Source

pub fn resolve_api_key_only(&self, provider: &str) -> Result<ApiKey>

Resolve an API key without falling back to stored OAuth credentials.

Source

pub fn resolve_secret_field( &self, provider: &str, field: &str, ) -> Result<String>

Resolve a named secret field for any stored provider/service.

Source

pub fn store_secret_fields( &mut self, provider: &str, fields: HashMap<String, String>, ) -> Result<()>

Store multiple named secret fields securely in the OS keychain and persist only metadata.

Source

pub fn secret_status(&self, provider: &str) -> Option<SecretStatus>

Check whether stored secret metadata points at readable secure-storage values.

Source

pub fn resolve_secret_fields( &self, provider: &str, ) -> Result<HashMap<String, String>>

Resolve all stored secret fields for a provider into a map.

Source

pub async fn resolve_chatgpt_oauth(&mut self) -> Result<ApiKey>

Resolve a ChatGPT/OpenAI OAuth token, preferring openai-codex when present.

Source

pub fn oauth_display_info(&self, provider: &str) -> Option<OAuthDisplayInfo>

Source

pub fn store( &mut self, provider: &str, credential: StoredCredential, ) -> Result<()>

Store a credential and persist to disk.

Source

pub async fn resolve_with_refresh(&mut self, provider: &str) -> Result<ApiKey>

Resolve API key, auto-refreshing expired OAuth tokens. Persists the refreshed credential to disk on success.

Source

pub fn is_oauth_expired(&self, provider: &str) -> bool

Check if the stored OAuth credential for a provider is expired.

Source

pub fn get_oauth(&self, provider: &str) -> Option<&OAuthCredential>

Get the stored OAuth credential for a provider (if any).

Source

pub async fn resolve_or_refresh<F, Fut>( &mut self, provider: &str, refresh_fn: F, ) -> Result<ApiKey>
where F: FnOnce(&str) -> Fut, Fut: Future<Output = Result<OAuthCredential>>,

Resolve API key with automatic OAuth refresh.

Source

pub fn remove(&mut self, provider: &str) -> Result<()>

Remove a stored credential (logout).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more