Struct Client

Source
pub struct Client<P> {
    pub provider: P,
    pub client_id: String,
    pub client_secret: String,
    pub redirect_uri: Option<String>,
}
Expand description

OAuth 2.0 client.

Fields§

§provider: P

OAuth provider.

§client_id: String

Client ID.

§client_secret: String

Client secret.

§redirect_uri: Option<String>

Redirect URI.

Implementations§

Source§

impl<P: Provider> Client<P>

Source

pub fn new( provider: P, client_id: String, client_secret: String, redirect_uri: Option<String>, ) -> Self

Creates a client.

§Examples
use inth_oauth2_async::Client;
use inth_oauth2_async::provider::google::Installed;

let client = Client::new(
    Installed,
    String::from("CLIENT_ID"),
    String::from("CLIENT_SECRET"),
    Some(String::from("urn:ietf:wg:oauth:2.0:oob")),
);
Source

pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Url

Returns an authorization endpoint URI to direct the user to.

See RFC 6749, section 3.1.

§Examples
use inth_oauth2_async::Client;
use inth_oauth2_async::provider::google::Installed;

let client = Client::new(
    Installed,
    String::from("CLIENT_ID"),
    String::from("CLIENT_SECRET"),
    Some(String::from("urn:ietf:wg:oauth:2.0:oob")),
);

let auth_uri = client.auth_uri(
    Some("https://www.googleapis.com/auth/userinfo.email"),
    None,
);
Source

pub async fn request_token( &self, http_client: &impl HttpClient, code: &str, ) -> Result<P::Token, ClientError>

Requests an access token using an authorization code.

See RFC 6749, section 4.1.3.

Source§

impl<P> Client<P>
where P: Provider, P::Token: Token<Refresh>,

Source

pub async fn refresh_token( &self, http_client: &impl HttpClient, token: P::Token, scope: Option<&str>, ) -> Result<P::Token, ClientError>

Refreshes an access token.

See RFC 6749, section 6.

Source

pub async fn ensure_token( &self, http_client: &impl HttpClient, token: P::Token, ) -> Result<P::Token, ClientError>

Ensures an access token is valid by refreshing it if necessary.

Trait Implementations§

Source§

impl<P: Clone> Clone for Client<P>

Source§

fn clone(&self) -> Client<P>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<P: Debug> Debug for Client<P>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<P: PartialEq> PartialEq for Client<P>

Source§

fn eq(&self, other: &Client<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Eq> Eq for Client<P>

Source§

impl<P> StructuralPartialEq for Client<P>

Auto Trait Implementations§

§

impl<P> Freeze for Client<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for Client<P>
where P: RefUnwindSafe,

§

impl<P> Send for Client<P>
where P: Send,

§

impl<P> Sync for Client<P>
where P: Sync,

§

impl<P> Unpin for Client<P>
where P: Unpin,

§

impl<P> UnwindSafe for Client<P>
where P: 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<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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 = 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<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
Source§

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

Source§

impl<T> MaybeSendSync for T