Skip to main content

AuthClient

Struct AuthClient 

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

Drives the OAuth 2.0 Authorization Code + PKCE flow against a Scribe server. This type does not open a browser or run a redirect listener; the embedding application is responsible for presenting AuthClient::authorization_url to the user and obtaining the resulting code however fits its own UI.

Implementations§

Source§

impl AuthClient

Source

pub fn new(http: Client, base_url: Url, client_id: impl Into<String>) -> Self

Source

pub fn authorization_url(&self, redirect_uri: &str, pkce: &PkceChallenge) -> Url

Builds the URL the user’s browser should be sent to. redirect_uri must match one registered for client_id server-side.

The authorize request is wrapped in the server’s /auth/logout redirect, so whatever session the browser is holding for this server is dropped before the authorize request is reached. Signing out only clears this device’s tokens: the browser’s cookie store belongs to the system, and an app has no way to reach into it. Without this, a session cookie surviving sign-out lets the next sign-in complete without asking for anything.

Clearing it at sign-in rather than at sign-out is what keeps the browser’s SSO session with the identity provider intact, so a returning user is asked for their email address instead of the whole credential flow.

Source

pub fn authorization_url_with_challenge( &self, redirect_uri: &str, pkce_challenge: &str, ) -> Url

AuthClient::authorization_url for callers that hold the challenge on its own rather than the whole PkceChallenge — the FFI hands the verifier to the host application to keep between the two halves of the flow, so by this point only the challenge string is left.

Source

pub async fn exchange_code( &self, redirect_uri: &str, code: &str, verifier: &str, ) -> Result<TokenSet, ScribeError>

Exchanges an authorization code (obtained after the user completes the browser flow at AuthClient::authorization_url) for a token set. verifier must be the same PkceChallenge used to build that URL.

§Errors

Returns ScribeError::InvalidGrant if the code or verifier is wrong or expired, or ScribeError::Http/ScribeError::Api on other request failures.

Source

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

Exchanges a refresh token for a new token set.

§Errors

Returns ScribeError::InvalidGrant if the refresh token is wrong, expired, or revoked, or ScribeError::Http/ScribeError::Api on other request failures.

Source

pub async fn revoke(&self, token: &str) -> Result<(), ScribeError>

Asks the server to invalidate a token, so signing out ends the session there and then rather than leaving a refresh token usable until it expires on its own.

Pass the refresh token when there is one: revoking it takes the access tokens issued alongside it with it. Passing an access token instead revokes only that token.

Per RFC 7009 the server answers successfully whether or not it recognised the token, so a success here means the request was accepted, not that something was necessarily revoked.

§Errors

Returns ScribeError::Http if the request could not be sent, or ScribeError::Api if the server refused it.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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