Skip to main content

CloudAuthenticator

Struct CloudAuthenticator 

Source
pub struct CloudAuthenticator { /* private fields */ }
Expand description

Ties the OIDC endpoints (Okta) and the SM API together for one environment.

Implementations§

Source§

impl CloudAuthenticator

Source

pub fn new( issuer: Url, client_id: impl Into<String>, sm_api_url: Url, capi_url: impl Into<String>, ) -> Self

Build for one environment. issuer/client_id drive the Okta flows, sm_api_url the key-minting exchange, and capi_url is recorded in the resulting profile.

Source

pub fn with_http_client(self, http: Client) -> Self

Use a caller-provided reqwest client (tests / shared client).

Source

pub fn device(&self) -> DeviceFlowClient

Device-authorization-grant client for headless / agent logins. The flow runs on the oauth2 crate’s own HTTP stack, so it does not share this authenticator’s SM client.

Source

pub fn loopback(&self) -> LoopbackFlowClient

Auth-code + PKCE loopback client for interactive human logins.

Source

pub async fn refresh(&self, refresh_token: &str) -> Result<TokenSet, AuthError>

Refresh an Okta refresh token for a fresh token set (Okta rotates it). The grant is flow-agnostic, so it goes straight through oidc rather than a specific flow client.

Source

pub async fn revoke_refresh_token( &self, refresh_token: &str, ) -> Result<(), AuthError>

Invalidate a stored refresh token at the identity provider.

Source

pub async fn list_accounts<F>( &self, tokens: &TokenSet, mfa_prompt: F, ) -> Result<AccountListing, AuthError>

List the accounts the signed-in user belongs to, minting nothing and switching nothing.

Source

pub async fn revoke_capi_key( &self, tokens: &TokenSet, account_id: Option<u64>, key_name: &str, ) -> Result<bool, AuthError>

Revoke a minted CAPI key by name from account_id, using a session established from tokens.

Returns whether a key of that name was found. Both the listing and the delete are scoped to the session’s account, so the caller has to say which account holds the key: a sign-in starts on the user’s server-side default, which is not necessarily the one a profile’s key was minted for. Passing None searches wherever the session lands, which is all an older profile that recorded no account can do.

Source

pub async fn complete_login( &self, tokens: &TokenSet, key_name: &str, flow: LoginFlow, account: AccountChoice, ) -> Result<MintedCredentials, AuthError>

Given tokens from a flow, run the SM exchange and mint a CAPI key named key_name.

Propagates AuthError::MfaRequired if the account is MFA-protected; use CloudAuthenticator::complete_login_with_mfa to supply codes interactively.

Source

pub async fn complete_login_with_mfa<F>( &self, tokens: &TokenSet, key_name: &str, flow: LoginFlow, account: AccountChoice, superseded: Option<SupersededKey>, mfa_prompt: F, ) -> Result<(MintedCredentials, Option<SupersededRevoker>), AuthError>

As CloudAuthenticator::complete_login, but mfa_prompt is consulted when SM challenges the login for multi-factor authentication.

mfa_prompt(factors, attempt) is called with the factor types SM offered (possibly empty) and a 1-based attempt number. Return Some(code) to submit a TOTP code, or None to give up — which surfaces the original AuthError::MfaRequired to the caller, the right behaviour when there is no terminal to prompt on.

Trait Implementations§

Source§

impl Clone for CloudAuthenticator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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