Skip to main content

cli_engine/auth/
mod.rs

1//! Auth provider abstraction and built-in auth helpers.
2//!
3//! Consumer CLIs normally register one or more [`AuthProvider`] implementations
4//! with [`crate::CliConfig`]. Middleware then resolves credentials before
5//! business logic runs and passes a [`Credential`] to command handlers.
6//!
7//! The module also contains an [`crate::auth::exec::ExecProvider`] for provider
8//! binaries that speak the JSON stdin/stdout contract.
9
10/// Built-in `auth login`, `auth status`, and `auth logout` command helpers.
11pub mod commands;
12mod credential;
13mod dispatcher;
14/// External process auth provider implementation.
15pub mod exec;
16
17use async_trait::async_trait;
18
19pub use commands::{
20    AuthLoginResult, AuthStatusEntry, auth_command_group, login_and_build, logout_result,
21    status_result, to_status_entry,
22};
23pub use credential::{CACHE_TTL, Credential};
24pub use dispatcher::{Dispatcher, SingleProvider, StatusEntry};
25pub use exec::{
26    ACTION_AUTHENTICATE, ACTION_LIST_ENVIRONMENTS, ACTION_LIST_REALMS, ACTION_LOGOUT,
27    ACTION_STATUS, AuthnRequest, EnvironmentsResponse, ExecProvider,
28};
29
30use crate::Result;
31
32#[async_trait]
33/// Named auth provider used by middleware and transport injectors.
34///
35/// Implementations own their credential cache strategy. The framework only
36/// routes calls and passes command context (`env`, colon command path, and tier).
37pub trait AuthProvider: Send + Sync + std::fmt::Debug {
38    /// Stable provider registration name, for example `primary` or `oauth`.
39    fn name(&self) -> &str;
40
41    /// Returns a credential for `env`, `command`, and `tier`.
42    async fn get_credential(&self, env: &str, command: &str, tier: &str) -> Result<Credential>;
43
44    /// Returns cached credential status for one environment.
45    async fn status(&self, env: &str) -> Result<Credential>;
46
47    /// Clears cached credentials for one environment.
48    async fn logout(&self, env: &str) -> Result<()>;
49
50    /// Lists environments with cached credentials.
51    async fn list_environments(&self) -> Result<Vec<String>>;
52}