pub struct OAuth2Config { /* private fields */ }Available on crate feature
oauth2 only.Expand description
OAuth2 authentication configuration.
Use OAuth2ConfigBuilder to create instances.
Implementations§
Source§impl OAuth2Config
impl OAuth2Config
Sourcepub fn client_credentials(
client_id: impl Into<String>,
client_secret: impl Into<SecureString>,
token_url: impl AsRef<str>,
) -> Result<OAuth2ConfigBuilder, OAuth2Error>
pub fn client_credentials( client_id: impl Into<String>, client_secret: impl Into<SecureString>, token_url: impl AsRef<str>, ) -> Result<OAuth2ConfigBuilder, OAuth2Error>
Creates a builder for client credentials flow.
Sourcepub fn pre_acquired(
client_id: impl Into<String>,
token_url: impl AsRef<str>,
access_token: impl Into<String>,
) -> Result<OAuth2ConfigBuilder, OAuth2Error>
pub fn pre_acquired( client_id: impl Into<String>, token_url: impl AsRef<str>, access_token: impl Into<String>, ) -> Result<OAuth2ConfigBuilder, OAuth2Error>
Creates a builder for a pre-acquired token.
Sourcepub async fn needs_token(&self) -> bool
pub async fn needs_token(&self) -> bool
Checks if a new token should be acquired.
Sourcepub async fn get_token(&self) -> Option<OAuth2Token>
pub async fn get_token(&self) -> Option<OAuth2Token>
Gets the cached token if available and not expired.
Sourcepub async fn set_token(&self, token: OAuth2Token)
pub async fn set_token(&self, token: OAuth2Token)
Stores a token in the cache.
Source§impl OAuth2Config
impl OAuth2Config
Sourcepub async fn acquire_token(&self) -> Result<OAuth2Token, OAuth2Error>
pub async fn acquire_token(&self) -> Result<OAuth2Token, OAuth2Error>
Acquires a new access token using the configured grant type.
This method handles:
- Client Credentials grant: fetches a new token from the token endpoint
- Pre-Acquired token: returns the cached token if available
§Errors
Returns an error if:
- Network request fails
- Token endpoint returns an error
- Response cannot be parsed
Sourcepub async fn get_valid_token(&self) -> Result<OAuth2Token, OAuth2Error>
pub async fn get_valid_token(&self) -> Result<OAuth2Token, OAuth2Error>
Gets a valid token, acquiring a new one if necessary.
This is the main entry point for getting an access token. It checks the cache first and only acquires a new token if needed.
Trait Implementations§
Source§impl Clone for OAuth2Config
impl Clone for OAuth2Config
Source§fn clone(&self) -> OAuth2Config
fn clone(&self) -> OAuth2Config
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 moreAuto Trait Implementations§
impl Freeze for OAuth2Config
impl !RefUnwindSafe for OAuth2Config
impl Send for OAuth2Config
impl Sync for OAuth2Config
impl Unpin for OAuth2Config
impl !UnwindSafe for OAuth2Config
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