pub struct OAuth2Client {
pub client_id: String,
pub authorization_endpoint: String,
pub scopes: Vec<String>,
pub use_pkce: bool,
/* private fields */
}Expand description
OAuth2 client for authorization code flow.
Fields§
§client_id: StringClient ID from provider.
Authorization endpoint.
scopes: Vec<String>Scopes to request.
use_pkce: boolUse PKCE for additional security.
Implementations§
Source§impl OAuth2Client
impl OAuth2Client
Sourcepub fn new(
client_id: impl Into<String>,
client_secret: impl Into<String>,
authorization_endpoint: impl Into<String>,
token_endpoint: impl Into<String>,
) -> Self
pub fn new( client_id: impl Into<String>, client_secret: impl Into<String>, authorization_endpoint: impl Into<String>, token_endpoint: impl Into<String>, ) -> Self
Create new OAuth2 client.
Sourcepub fn with_scopes(self, scopes: Vec<String>) -> Self
pub fn with_scopes(self, scopes: Vec<String>) -> Self
Set scopes for request.
Generate authorization URL.
Returns an AuthorizationRequest containing the URL, the CSRF state
value (must be stored and verified at callback), and an optional PKCE
challenge (when use_pkce = true; the code_verifier must be stored
and sent during token exchange).
Sourcepub async fn exchange_code(
&self,
code: &str,
redirect_uri: &str,
) -> Result<TokenResponse, String>
pub async fn exchange_code( &self, code: &str, redirect_uri: &str, ) -> Result<TokenResponse, String>
Exchange authorization code for tokens.
§Errors
Returns an error if the HTTP request to the token endpoint fails or the response
cannot be parsed as a TokenResponse.
Sourcepub async fn refresh_token(
&self,
refresh_token: &str,
) -> Result<TokenResponse, String>
pub async fn refresh_token( &self, refresh_token: &str, ) -> Result<TokenResponse, String>
Refresh access token using a refresh token.
§Errors
Propagates errors from the token endpoint request (network failure, non-2xx HTTP status, oversized response body, or JSON parse error).
Trait Implementations§
Source§impl Clone for OAuth2Client
impl Clone for OAuth2Client
Source§fn clone(&self) -> OAuth2Client
fn clone(&self) -> OAuth2Client
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for OAuth2Client
impl !RefUnwindSafe for OAuth2Client
impl Send for OAuth2Client
impl Sync for OAuth2Client
impl Unpin for OAuth2Client
impl UnsafeUnpin for OAuth2Client
impl !UnwindSafe for OAuth2Client
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more