Struct inth_oauth2::client::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
sourceimpl<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::Client;
use inth_oauth2::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::Client;
use inth_oauth2::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 fn request_token(
&self,
http_client: &Client,
code: &str
) -> Result<P::Token, ClientError>
pub fn request_token(
&self,
http_client: &Client,
code: &str
) -> Result<P::Token, ClientError>
Requests an access token using an authorization code.
sourceimpl<P> Client<P>where
P: Provider,
P::Token: Token<Refresh>,
impl<P> Client<P>where
P: Provider,
P::Token: Token<Refresh>,
sourcepub fn refresh_token(
&self,
http_client: &Client,
token: P::Token,
scope: Option<&str>
) -> Result<P::Token, ClientError>
pub fn refresh_token(
&self,
http_client: &Client,
token: P::Token,
scope: Option<&str>
) -> Result<P::Token, ClientError>
Refreshes an access token.
See RFC 6749, section 6.
sourcepub fn ensure_token(
&self,
http_client: &Client,
token: P::Token
) -> Result<P::Token, ClientError>
pub fn ensure_token(
&self,
http_client: &Client,
token: P::Token
) -> Result<P::Token, ClientError>
Ensures an access token is valid by refreshing it if necessary.
Trait Implementations
sourceimpl<P: PartialEq> PartialEq<Client<P>> for Client<P>
impl<P: PartialEq> PartialEq<Client<P>> for Client<P>
impl<P: Eq> Eq for Client<P>
impl<P> StructuralEq for Client<P>
impl<P> StructuralPartialEq for Client<P>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.