Skip to main content

OAuthTokenData

Struct OAuthTokenData 

Source
pub struct OAuthTokenData {
    pub access_token: AccessToken,
    pub refresh_token: RefreshToken,
    pub expires_at: Option<DateTime<Utc>>,
    pub token_type: String,
    pub scopes: Option<Vec<String>>,
    pub client_id: Option<String>,
    pub client_secret: Option<String>,
    pub proxy_url: Option<String>,
}
Expand description

OAuth 2.0 token data, serializable to/from JSON for file storage.

Contains the access token, refresh token, and optional expiration time. Token values use oauth2::AccessToken and oauth2::RefreshToken types, with custom serde implementations for JSON file persistence.

Fields§

§access_token: AccessToken

The OAuth 2.0 access token.

§refresh_token: RefreshToken

The OAuth 2.0 refresh token.

§expires_at: Option<DateTime<Utc>>

When the access token expires, if known. Stored as an absolute timestamp for persistence (unlike the relative expires_in from the token response).

§token_type: String

The token type — must be “bearer” (case-insensitive).

Validated during deserialization: rejects non-bearer token types to catch corrupted or tampered token files early. The value is normalized to lowercase on load.

§scopes: Option<Vec<String>>

OAuth 2.0 scopes granted by the authorization server.

Stored as a list of scope strings (e.g. ["OAuth2Read", "OAuth2Write"]). None when the server did not return scopes or the token predates scope tracking.

§client_id: Option<String>

OAuth client ID used to obtain these tokens.

Stored alongside tokens so the MCP server can refresh them without requiring separate configuration. Written by the OpenCode plugin during opencode auth login.

§client_secret: Option<String>

OAuth client secret used to obtain these tokens.

Stored alongside tokens so the MCP server can refresh them without requiring separate configuration. Written by the OpenCode plugin during opencode auth login.

Mutually exclusive with proxy_url — tokens use either direct (client_secret) or proxy-based refresh.

§proxy_url: Option<String>

OAuth token exchange proxy URL.

When present, the MCP server refreshes tokens via this proxy (which holds the client secret) instead of contacting Onshape directly. Written by the OpenCode plugin when the user authenticates via the proxy flow.

Mutually exclusive with client_secret.

Implementations§

Source§

impl OAuthTokenData

Source

pub fn is_expired(&self, now: DateTime<Utc>) -> bool

Checks whether the access token has expired relative to the given timestamp.

Returns true if expires_at is set and is before or equal to now. Returns false if expires_at is None (expiration unknown).

Source

pub fn is_expiring_soon(&self, now: DateTime<Utc>, margin: Duration) -> bool

Returns true if the token expires within margin of now, or is already expired.

Returns false if expires_at is None (unknown expiry — assume valid).

Source§

impl OAuthTokenData

Source

pub fn from_response(response: &BasicTokenResponse, now: DateTime<Utc>) -> Self

Converts an oauth2::basic::BasicTokenResponse into OAuthTokenData.

The relative expires_in duration from the token response is converted to an absolute expires_at timestamp using the provided now value. Accepting now as a parameter (instead of calling Utc::now()) keeps this function pure and testable with exact timestamps.

Source§

impl OAuthTokenData

Source

pub fn from_raw( access_token: String, refresh_token: String, expires_at: Option<DateTime<Utc>>, token_type: String, scopes: Option<Vec<String>>, ) -> Self

Build token data from raw field values (e.g. parsed from a proxy response).

The caller is responsible for preserving client_id, client_secret, and proxy_url from the previous token data.

Trait Implementations§

Source§

impl Clone for OAuthTokenData

Source§

fn clone(&self) -> OAuthTokenData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OAuthTokenData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OAuthTokenData

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for OAuthTokenData

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,