Skip to main content

NativeAuthFlow

Struct NativeAuthFlow 

Source
pub struct NativeAuthFlow<S: ConsentScopes> { /* private fields */ }
Expand description

Native-app OAuth composition root. See the module docs.

S is the scope tier: it determines what goes on the authorize wire, what the grant is checked against, and what the yielded token source is witnessed for — one type parameter across the whole credential story.

Implementations§

Source§

impl<S: ConsentScopes> NativeAuthFlow<S>

Source

pub async fn new(config: NativeConfig) -> Result<Self, NativeAuthInitError>

Construct a flow, fetching the authorization server’s discovery document once.

No OAuth client is built here — a native client’s redirect URI does not exist until a loopback socket is bound, so the client is assembled per use from the discovered endpoints.

§Errors

NativeAuthInitError::Discovery if the document cannot be fetched or fails RFC 8414 §3.3 issuer validation.

Source

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

Begin an authorization attempt; returns the URL to open in the browser.

redirect_uri is the loopback address the consumer has already bound, forwarded verbatim to both legs of the flow. Pass it exactly as the listener reports it — it is never parsed, for the same byte-identity reason as NativeConfig::with_resource, and RFC 6749 §4.1.3 requires the token leg to repeat it unchanged.

Any attempt already pending is discarded: at most one authorization can be in flight, and the newest supersedes it. The abandoned attempt’s state can then never be completed, which is the correct outcome for a flow the user restarted.

Emits no nonce — there is no id_token for one to bind to.

Source

pub fn token_source<T: TokenStore>( &self, store: T, ) -> Result<RefreshTokenSource<AuthClient, T, S>, NativeAuthInitError>

A renewing token source over an already-held refresh token.

This is the restart path: a native app relaunching with a credential in its keystore has no authorization code to exchange, and needs no browser round trip. store must already hold the refresh token.

The returned source is witnessed for S on the same terms as complete’s — the guarantee attaches to use, and every renewal re-checks the grant. So this constructor needs no proof from its caller and still cannot yield an unchecked token.

§Errors

NativeAuthInitError::OAuthClient if the HTTP client cannot be built.

Source

pub async fn complete<T: TokenStore>( &self, callback_query: &str, store: T, ) -> Result<RefreshTokenSource<AuthClient, T, S>, CallbackError>

Complete an attempt from the raw redirect query string.

callback_query is everything after the ? in the redirect the loopback listener received — passed through untouched. This method parses it, enforces single-use state, exchanges the code with the stored PKCE verifier, checks the granted scope covers S, persists the refresh token into store, and returns the renewing source.

§Errors

See CallbackError. Note that AuthorizationDenied is the ordinary “user said no” outcome, not a defect.

Trait Implementations§

Source§

impl<S: ConsentScopes> Debug for NativeAuthFlow<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for NativeAuthFlow<S>

§

impl<S> RefUnwindSafe for NativeAuthFlow<S>
where S: RefUnwindSafe,

§

impl<S> Send for NativeAuthFlow<S>

§

impl<S> Sync for NativeAuthFlow<S>

§

impl<S> Unpin for NativeAuthFlow<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for NativeAuthFlow<S>

§

impl<S> UnwindSafe for NativeAuthFlow<S>
where S: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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