pub struct OAuthCredential {
pub client_id: String,
pub access_token: String,
pub refresh_token: Option<String>,
pub expires_at: Option<u64>,
pub granted_scopes: Vec<String>,
}Expand description
Credential for an OAuth provider.
Fields§
§client_id: String§access_token: String§refresh_token: Option<String>§expires_at: Option<u64>Unix timestamp in milliseconds when the token expires.
granted_scopes: Vec<String>Scopes the authorization server granted with this token.
Implementations§
Source§impl OAuthCredential
impl OAuthCredential
Sourcepub fn from_token_response<T: TokenResponse>(
client_id: String,
token_response: &T,
) -> Self
pub fn from_token_response<T: TokenResponse>( client_id: String, token_response: &T, ) -> Self
Build an OAuthCredential from an OAuth2 token response.
Sourcepub fn needs_refresh(&self) -> bool
pub fn needs_refresh(&self) -> bool
Whether the access token is expired or expiring within the refresh skew.
Sourcepub fn expires_in(&self) -> Option<Duration>
pub fn expires_in(&self) -> Option<Duration>
Time remaining before the access token expires, if known and still in the future.
Sourcepub async fn refresh(self, token_url: &TokenUrl) -> Result<Self, OAuthError>
pub async fn refresh(self, token_url: &TokenUrl) -> Result<Self, OAuthError>
Exchange the refresh token for a new access token.
Preserves the existing refresh token if the response doesn’t include a rotated one.
Returns NoCredentials if the credential has no refresh token to exchange.
Trait Implementations§
Source§impl Clone for OAuthCredential
impl Clone for OAuthCredential
Source§fn clone(&self) -> OAuthCredential
fn clone(&self) -> OAuthCredential
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 OAuthCredential
impl Debug for OAuthCredential
Source§impl<'de> Deserialize<'de> for OAuthCredential
impl<'de> Deserialize<'de> for OAuthCredential
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 OAuthCredential
impl RefUnwindSafe for OAuthCredential
impl Send for OAuthCredential
impl Sync for OAuthCredential
impl Unpin for OAuthCredential
impl UnsafeUnpin for OAuthCredential
impl UnwindSafe for OAuthCredential
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