pub struct OAuth2Auth {
pub token_url: String,
pub client_id: String,
pub client_secret: Option<String>,
pub grant_type: OAuth2GrantType,
pub access_token: Option<String>,
pub refresh_token: Option<String>,
pub expires_at: Option<i64>,
pub scopes: Vec<String>,
pub code_verifier: Option<String>,
pub authorization_code: Option<String>,
}Expand description
OAuth2 authentication configuration with token refresh support
Fields§
§token_url: StringOAuth2 token endpoint URL
client_id: StringClient ID
client_secret: Option<String>Client secret (optional for PKCE)
grant_type: OAuth2GrantTypeGrant type
access_token: Option<String>Access token
refresh_token: Option<String>Refresh token
expires_at: Option<i64>Token expiry time (Unix timestamp)
scopes: Vec<String>Requested scopes
code_verifier: Option<String>PKCE code verifier (for authorization code flow)
Authorization code (for authorization code flow)
Implementations§
Source§impl OAuth2Auth
impl OAuth2Auth
Sourcepub fn client_credentials(
token_url: impl Into<String>,
client_id: impl Into<String>,
client_secret: impl Into<String>,
) -> Self
pub fn client_credentials( token_url: impl Into<String>, client_id: impl Into<String>, client_secret: impl Into<String>, ) -> Self
Create new OAuth2 authentication with client credentials
Create new OAuth2 authentication with authorization code
Sourcepub fn with_tokens(
token_url: impl Into<String>,
client_id: impl Into<String>,
client_secret: Option<String>,
access_token: impl Into<String>,
refresh_token: impl Into<String>,
) -> Self
pub fn with_tokens( token_url: impl Into<String>, client_id: impl Into<String>, client_secret: Option<String>, access_token: impl Into<String>, refresh_token: impl Into<String>, ) -> Self
Create OAuth2 authentication with existing access and refresh tokens
Sourcepub fn with_scopes(self, scopes: Vec<String>) -> Self
pub fn with_scopes(self, scopes: Vec<String>) -> Self
Add scopes to the OAuth2 request
Sourcepub fn with_pkce(self, code_verifier: impl Into<String>) -> Self
pub fn with_pkce(self, code_verifier: impl Into<String>) -> Self
Set PKCE code verifier (for authorization code flow)
Sourcepub fn is_token_expired(&self) -> bool
pub fn is_token_expired(&self) -> bool
Check if the token is expired
Sourcepub fn header_value(&self) -> Option<String>
pub fn header_value(&self) -> Option<String>
Get the Authorization header value
Sourcepub async fn request_token(&mut self) -> Result<()>
pub async fn request_token(&mut self) -> Result<()>
Request a new access token from the OAuth2 server
Sourcepub async fn refresh_if_needed(&mut self) -> Result<bool>
pub async fn refresh_if_needed(&mut self) -> Result<bool>
Refresh the access token if expired
Trait Implementations§
Source§impl Clone for OAuth2Auth
impl Clone for OAuth2Auth
Source§fn clone(&self) -> OAuth2Auth
fn clone(&self) -> OAuth2Auth
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OAuth2Auth
impl Debug for OAuth2Auth
Source§impl<'de> Deserialize<'de> for OAuth2Auth
impl<'de> Deserialize<'de> for OAuth2Auth
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for OAuth2Auth
impl RefUnwindSafe for OAuth2Auth
impl Send for OAuth2Auth
impl Sync for OAuth2Auth
impl Unpin for OAuth2Auth
impl UnwindSafe for OAuth2Auth
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