pub struct OAuthCredential {
pub client_id: String,
pub access_token: String,
pub refresh_token: Option<String>,
pub expires_at: Option<u64>,
}Expand description
Credential for a non-MCP 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.
Implementations§
Source§impl OAuthCredential
impl OAuthCredential
pub fn new( client_id: impl Into<String>, access_token: impl Into<String>, ) -> Self
pub fn refresh_token(self, refresh_token: impl Into<String>) -> Self
pub fn expires_at(self, expires_at: u64) -> Self
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§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
impl Eq for OAuthCredential
Source§impl PartialEq for OAuthCredential
impl PartialEq for OAuthCredential
Source§impl Serialize for OAuthCredential
impl Serialize for OAuthCredential
impl StructuralPartialEq for OAuthCredential
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.