pub struct AuthClient { /* private fields */ }Expand description
The unauthenticated entry point: turns credentials (or a persisted session)
into an authenticated Session.
Implementations§
Source§impl AuthClient
impl AuthClient
Sourcepub fn new(base_url: &str) -> Result<Self, AuthError>
pub fn new(base_url: &str) -> Result<Self, AuthError>
Build a client against the auth base URL (e.g. https://api.example.com/auth).
Sourcepub fn with_cohort_hash(self, cohort_hash: String) -> Self
pub fn with_cohort_hash(self, cohort_hash: String) -> Self
Attach the advisory device-cohort hash that rides every subsequent session-creation request (login/register) from this client.
The value is a lowercase-hex SHA-256 digest computed by the platform app from
its primary identifier and the account’s user_id
(crate::cohort::compute_cohort_hash). It is a grouping aid only — the
server never reads it for any authorization decision. Not setting it
(the default) is fully legal: nothing is sent and the server behaves
identically.
Sourcepub async fn login(
&self,
email: &str,
password: &str,
) -> Result<LoginOutcome, AuthError>
pub async fn login( &self, email: &str, password: &str, ) -> Result<LoginOutcome, AuthError>
Authenticate with email + password, returning an authenticated Session.
If a cohort hash is configured (with_cohort_hash)
it rides the request body; otherwise the field is omitted entirely.
Sourcepub async fn sign_in_options(&self) -> Result<SignInOptions, AuthError>
pub async fn sign_in_options(&self) -> Result<SignInOptions, AuthError>
Read how this server signs people in from its unauthenticated
.well-known/capsule/server-info record (one generated call, nothing sent but the
handshake).
§Errors
AuthError::Network when the server cannot be reached, AuthError::Unexpected for a
status the record does not answer with, and AuthError::MalformedResponse for a body
that is not the record. A caller treats every one as “unknown” rather than as a refusal:
the record is advisory.
Sourcepub async fn begin_oidc_login(
&self,
redirect_uri: &str,
) -> Result<OidcAuthorization, AuthError>
pub async fn begin_oidc_login( &self, redirect_uri: &str, ) -> Result<OidcAuthorization, AuthError>
Begin a sign-in through the server’s identity provider.
redirect_uri is where the provider will send the person back — this client’s own
callback, which the server admits if it is the deployment’s configured one or a loopback
IP literal on any port (the shape a CLI’s or desktop app’s listener has). What comes back
is where to send the person, the state the redirect will echo, and the secret binding
this client keeps: a fresh one per ceremony, of which only the hash is sent.
§Errors
AuthError::OidcNotConfigured when the server has no provider,
AuthError::OidcRedirectInvalid when it refuses the redirect.
Sourcepub async fn complete_oidc_login(
&self,
pending: &OidcAuthorization,
redirect_state: &str,
code: &str,
) -> Result<LoginOutcome, AuthError>
pub async fn complete_oidc_login( &self, pending: &OidcAuthorization, redirect_state: &str, code: &str, ) -> Result<LoginOutcome, AuthError>
Finish a sign-in through the identity provider with what its redirect carried.
Answers a LoginOutcome exactly as login does — a session, or a
second-factor challenge for an account that enrolled one — and the configured cohort hash
rides this request, because this is the one that opens the session.
pending is what begin_oidc_login answered;
redirect_state and code are what the provider’s redirect carried. A redirect whose
state is not the one this client began is refused here, before anything is sent: it is
someone else’s ceremony arriving at this client (RFC 6749 §10.12). The server makes the
same refusal on the binding, which is what holds when a client skips this check.
§Errors
AuthError::OidcRejected for a redirect carrying another ceremony’s state, a spent or
expired state, a refused exchange or a refused ID token (start again);
AuthError::OidcAddressTaken when the provider asserted an address that already has a
local account.
Sourcepub async fn begin_oidc_device_login(
&self,
) -> Result<OidcDeviceAuthorization, AuthError>
pub async fn begin_oidc_device_login( &self, ) -> Result<OidcDeviceAuthorization, AuthError>
Begin a sign-in through the server’s identity provider for a client with no browser of its own (RFC 8628, issue #635).
What comes back is what to show the person and the handle to poll with, bound to this client by a fresh secret of which only the hash is sent.
§Errors
AuthError::OidcNotConfigured when the server has no provider,
AuthError::OidcDeviceUnsupported when its provider does not offer the grant,
AuthError::RateLimited when too many were begun.
Sourcepub async fn poll_oidc_device_login(
&self,
pending: &OidcDeviceAuthorization,
) -> Result<OidcDevicePoll, AuthError>
pub async fn poll_oidc_device_login( &self, pending: &OidcDeviceAuthorization, ) -> Result<OidcDevicePoll, AuthError>
Poll a device sign-in once (RFC 8628, issue #635).
OidcDevicePoll::Pending and OidcDevicePoll::SlowDown are RFC 8628’s “keep
polling”; OidcDevicePoll::Complete is exactly what login
answers — a session, or a second-factor challenge — and the configured cohort hash rides
this request, because it is the one that opens the session. Waiting is the caller’s: this
sends one request and returns.
§Errors
AuthError::OidcDeviceDenied when the person declined, AuthError::OidcDeviceExpired
when the ceremony is over, AuthError::OidcRejected for a refused exchange or ID
token, AuthError::OidcAddressTaken as on the callback.
Sourcepub async fn verify_second_factor(
&self,
mfa_token: &SecretString,
totp_code: &str,
) -> Result<Session, AuthError>
pub async fn verify_second_factor( &self, mfa_token: &SecretString, totp_code: &str, ) -> Result<Session, AuthError>
Complete a sign-in with the code an authenticator app is showing.
mfa_token is the challenge LoginOutcome::SecondFactorRequired carried. It is good
once and for five minutes; a code is good once, full stop, so a retry after a wrong code
re-uses the same challenge and a retry after a right one has to start from the password.
Trait Implementations§
Source§impl Clone for AuthClient
impl Clone for AuthClient
Source§fn clone(&self) -> AuthClient
fn clone(&self) -> AuthClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for AuthClient
impl !UnwindSafe for AuthClient
impl Freeze for AuthClient
impl Send for AuthClient
impl Sync for AuthClient
impl Unpin for AuthClient
impl UnsafeUnpin for AuthClient
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more