pub struct AuthManager { /* private fields */ }Expand description
Central manager providing a single source of truth for auth.json derived
authentication data. It loads once (or on preference change) and then
hands out cloned CodexAuth values so the rest of the program has a
consistent snapshot.
External modifications to auth.json will NOT be observed until
reload() is called explicitly. This matches the design goal of avoiding
different parts of the program seeing inconsistent auth data mid‑run.
Implementations§
Source§impl AuthManager
impl AuthManager
Sourcepub async fn new(
codex_home: PathBuf,
enable_codex_api_key_env: bool,
auth_credentials_store_mode: AuthCredentialsStoreMode,
forced_chatgpt_workspace_id: Option<Vec<String>>,
chatgpt_base_url: Option<String>,
keyring_backend_kind: AuthKeyringBackendKind,
auth_route_config: AuthRouteConfig,
) -> Self
pub async fn new( codex_home: PathBuf, enable_codex_api_key_env: bool, auth_credentials_store_mode: AuthCredentialsStoreMode, forced_chatgpt_workspace_id: Option<Vec<String>>, chatgpt_base_url: Option<String>, keyring_backend_kind: AuthKeyringBackendKind, auth_route_config: AuthRouteConfig, ) -> Self
Create a new manager loading the initial auth using the provided
preferred auth method. Errors loading auth are swallowed; auth() will
simply return None in that case so callers can treat it as an
unauthenticated state.
Sourcepub fn from_auth_for_testing(auth: CodexAuth) -> Arc<Self>
pub fn from_auth_for_testing(auth: CodexAuth) -> Arc<Self>
Create an AuthManager with a specific CodexAuth, for testing only.
Sourcepub fn from_auth_for_testing_with_home(
auth: CodexAuth,
codex_home: PathBuf,
) -> Arc<Self>
pub fn from_auth_for_testing_with_home( auth: CodexAuth, codex_home: PathBuf, ) -> Arc<Self>
Create an AuthManager with a specific CodexAuth and codex home, for testing only.
pub fn external_bearer_only(config: ModelProviderAuthInfo) -> Arc<Self>
Sourcepub fn auth_cached(&self) -> Option<CodexAuth>
pub fn auth_cached(&self) -> Option<CodexAuth>
Current cached auth (clone) without attempting a refresh.
Sourcepub fn auth_change_receiver(&self) -> Receiver<u64>
pub fn auth_change_receiver(&self) -> Receiver<u64>
Subscribes to cached auth changes that can affect request recovery.
pub fn refresh_failure_for_auth( &self, auth: &CodexAuth, ) -> Option<RefreshTokenFailedError>
Sourcepub async fn auth(&self) -> Option<CodexAuth>
pub async fn auth(&self) -> Option<CodexAuth>
Current cached auth (clone). May be None if not logged in or load failed.
For managed ChatGPT auth that needs a proactive refresh, first performs
a guarded reload and then refreshes only if the on-disk auth is unchanged.
pub async fn agent_identity_auth( &self, policy: AgentIdentityAuthPolicy, session_source: SessionSource, ) -> Result<Option<AgentIdentityAuth>>
Sourcepub async fn reload(&self) -> bool
pub async fn reload(&self) -> bool
Reloads auth from the active source. Returns whether the auth value changed.
pub async fn set_external_auth( &self, external_auth: Arc<dyn ExternalAuth>, ) -> Result<(), RefreshTokenError>
pub fn clear_external_auth(&self)
pub fn set_forced_chatgpt_workspace_id(&self, workspace_id: Option<Vec<String>>)
pub fn forced_chatgpt_workspace_id(&self) -> Option<Vec<String>>
pub fn has_external_auth(&self) -> bool
pub fn is_external_chatgpt_auth_active(&self) -> bool
pub fn codex_api_key_env_enabled(&self) -> bool
Convenience constructor returning an Arc wrapper.
Convenience constructor returning an Arc wrapper from resolved config.
Sourcepub async fn refresh_token(&self) -> Result<(), RefreshTokenError>
pub async fn refresh_token(&self) -> Result<(), RefreshTokenError>
Attempt to refresh the token by first performing a guarded reload from the active auth source. If the loaded token differs from the cached token, we can assume that the source already refreshed it. Otherwise, ask the token authority to refresh.
Attempt to refresh the current auth token from the authority that issued it and update the shared cache. If the token refresh fails, returns the error to the caller.
Sourcepub async fn logout(&self) -> Result<bool>
pub async fn logout(&self) -> Result<bool>
Log out by deleting the on‑disk auth.json (if present). Returns Ok(true) if a file was removed, Ok(false) if no auth file existed. On success, reloads the in‑memory auth cache so callers immediately observe the unauthenticated state.
pub async fn logout_with_revoke(&self) -> Result<bool>
Sourcepub fn get_api_auth_mode(&self) -> Option<AuthMode>
pub fn get_api_auth_mode(&self) -> Option<AuthMode>
Returns the precise kind of credentials backing the current authentication.
Sourcepub fn auth_mode(&self) -> Option<AuthMode>
pub fn auth_mode(&self) -> Option<AuthMode>
Returns the effective backend auth mode for the current authentication.
pub fn current_auth_uses_codex_backend(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AuthManager
impl !RefUnwindSafe for AuthManager
impl !UnwindSafe for AuthManager
impl Send for AuthManager
impl Sync for AuthManager
impl Unpin for AuthManager
impl UnsafeUnpin for AuthManager
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,
impl<T> AsTypeStaticRegistered for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
impl<T> HasTyVTable for Twhere
T: ?Sized,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request