pub struct OAuth2Flow {
    pub client_id: String,
    pub client_secret: String,
    pub init_endpoint: String,
    pub exchange_endpoint: String,
    pub refresh_endpoint: String,
    pub redirect_uri: String,
}
Expand description

The main entry point for taking the user through OAuth2 flow.

Fields§

§client_id: String§client_secret: String§init_endpoint: String

The endpoint to initialize the flow. (Step 1)

§exchange_endpoint: String

The endpoint to exchange the code for an access token. (Step 2)

§refresh_endpoint: String

The endpoint to refresh the access token.

§redirect_uri: String

Implementations§

source§

impl OAuth2Flow

source

pub fn create_authorization_url(&self, init: Initialize) -> Uri

Step 1: Send the user to the authorization URL.

After performing the exchange, you will get an ExchangeResponse. Depending on the PromptType provided here, that response may not contain a refresh_token.

If the value is select_account, it will have a refresh_token only on the first exchange. Afterward, it will be missing.

If the value is consent, the response will always have a refresh_token. The reason to avoid consent except when necessary is because it will require the user to re-accept the permissions (i.e. longer user flow, causing drop-off).

source

pub fn extract_code(&self, url: &str) -> Result<RedirectData>

Step 2a: Extract the code from the redirect URL. url can either be the full url, or a path_and_query string, e.g. “/foo?code=abc&state=def” The input will be url-decoded (percent-decoded).

source

pub fn create_exchange_data(&self, code: String) -> ExchangeData<'_>

source

pub async fn exchange(&self, code: String) -> InMemoryResult<ExchangeResponse>

Step 2b: Using RedirectedParams.code, POST to the exchange_endpoint to get the access token.

source

pub fn middleware_from_exchange( &self, exchange: ExchangeResponse ) -> Result<OAuth2, MissingRefreshToken>

Step 3: Use the exchange response to create a middleware. You can also use bearer_middleware. This method can fail if the ExchangeResponse is missing the refresh token. This will happen in “re-auth” situations when prompt=“consent” was not used. See Self::create_authorization_url docs for more.

As the middleware makes requests, the access_token will be refreshed automatically when it expires. If you want to store the updated access_token (recommended), set the OAuth2 callback field.

source

pub fn bearer_middleware(&self, access: String, refresh: String) -> OAuth2

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more