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>
impl<P: Provider> Client<P>
Sourcepub fn new(
provider: P,
client_id: String,
client_secret: String,
redirect_uri: Option<String>,
) -> Self
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")),
);
Sourcepub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Url
pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> Url
Returns an authorization endpoint URI to direct the user to.
§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,
);
Sourcepub async fn request_token(
&self,
http_client: &impl HttpClient,
code: &str,
) -> Result<P::Token, ClientError>
pub async fn request_token( &self, http_client: &impl HttpClient, code: &str, ) -> Result<P::Token, ClientError>
Requests an access token using an authorization code.
Source§impl<P> Client<P>
impl<P> Client<P>
Sourcepub async fn refresh_token(
&self,
http_client: &impl HttpClient,
token: P::Token,
scope: Option<&str>,
) -> Result<P::Token, ClientError>
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.
Sourcepub async fn ensure_token(
&self,
http_client: &impl HttpClient,
token: P::Token,
) -> Result<P::Token, ClientError>
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§
impl<P: Eq> Eq for Client<P>
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> 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.