pub struct ProviderAuthRegistry { /* private fields */ }Expand description
Provider authentication registry
Manages authentication for multiple providers with priority-based resolution. All resolution is file-based — no environment variables are used.
Priority:
- Runtime override (CLI –api-key)
- Stored credential (auth.json) ← Primary source
- OAuth token (with auto-refresh)
- Ambient credentials (AWS IAM via ~/.aws, Google ADC via ~/.config/gcloud)
- Fallback resolver (custom provider config from models.json)
Implementations§
Source§impl ProviderAuthRegistry
impl ProviderAuthRegistry
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a registry with default providers pre-registered
Sourcepub fn register_defaults(&mut self)
pub fn register_defaults(&mut self)
Register default providers
Sourcepub fn register_api_key(&mut self, provider: &str, api_key: Option<String>)
pub fn register_api_key(&mut self, provider: &str, api_key: Option<String>)
Register an API key provider
Sourcepub fn register_oauth(&mut self, provider: &str, token: OAuthTokenInfo)
pub fn register_oauth(&mut self, provider: &str, token: OAuthTokenInfo)
Register an OAuth provider
Sourcepub fn register_ambient<F>(&mut self, provider: &str, check_fn: F)
pub fn register_ambient<F>(&mut self, provider: &str, check_fn: F)
Register an ambient credential provider
Sourcepub fn register<P: ProviderAuth + 'static>(&mut self, provider: &str, auth: P)
pub fn register<P: ProviderAuth + 'static>(&mut self, provider: &str, auth: P)
Register a custom provider auth implementation
Sourcepub fn set_runtime_key(&self, provider: &str, api_key: String)
pub fn set_runtime_key(&self, provider: &str, api_key: String)
Set a runtime API key override
Sourcepub fn remove_runtime_key(&self, provider: &str)
pub fn remove_runtime_key(&self, provider: &str)
Remove a runtime override
Sourcepub fn set_fallback_resolver<F>(&self, resolver: F)
pub fn set_fallback_resolver<F>(&self, resolver: F)
Set a fallback resolver for providers not in the registry
Sourcepub fn clear_fallback_resolver(&self)
pub fn clear_fallback_resolver(&self)
Remove fallback resolver
Sourcepub fn get_api_key(&self, provider: &str) -> Option<String>
pub fn get_api_key(&self, provider: &str) -> Option<String>
Get API key for a provider using the resolution chain
Priority:
- Runtime override (–api-key)
- Stored credential (auth.json)
- OAuth token
- Ambient credentials (AWS IAM, Google ADC via SDK/filesystem)
- Fallback resolver (custom provider config from models.json)
- Environment variable (last resort for CI/CD)
Sourcepub fn has_auth(&self, provider: &str) -> bool
pub fn has_auth(&self, provider: &str) -> bool
Check if any auth is configured for a provider
Note: Environment variables don’t count as “configured” —
they are a last-resort fallback. Use oxicode setup to store
credentials properly in auth.json for persistent authentication.
Sourcepub fn needs_oauth_refresh(&self, provider: &str) -> bool
pub fn needs_oauth_refresh(&self, provider: &str) -> bool
Check if an OAuth provider needs refresh
Sourcepub fn set_oauth_token(&mut self, provider: &str, token: OAuthTokenInfo)
pub fn set_oauth_token(&mut self, provider: &str, token: OAuthTokenInfo)
Update OAuth token for a provider
Sourcepub fn set_api_key(&mut self, provider: &str, api_key: String)
pub fn set_api_key(&mut self, provider: &str, api_key: String)
Update API key directly
Sourcepub fn list_providers(&self) -> Vec<String>
pub fn list_providers(&self) -> Vec<String>
List all providers with configured auth
Sourcepub fn get_auth_status(&self, provider: &str) -> AuthStatus
pub fn get_auth_status(&self, provider: &str) -> AuthStatus
Get auth status for a provider