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: AccessTokenThe OAuth 2.0 access token.
refresh_token: RefreshTokenThe 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: StringThe 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
impl OAuthTokenData
Sourcepub fn is_expired(&self, now: DateTime<Utc>) -> bool
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§impl OAuthTokenData
impl OAuthTokenData
Sourcepub fn from_response(response: &BasicTokenResponse, now: DateTime<Utc>) -> Self
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
impl OAuthTokenData
Sourcepub fn from_raw(
access_token: String,
refresh_token: String,
expires_at: Option<DateTime<Utc>>,
token_type: String,
scopes: Option<Vec<String>>,
) -> Self
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
impl Clone for OAuthTokenData
Source§fn clone(&self) -> OAuthTokenData
fn clone(&self) -> OAuthTokenData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more