Skip to content

Commit f4b7246

Browse files
committed
feat(oauth): add OAuth::from_token for server-side token usage
1 parent b11d186 commit f4b7246

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

rust/crates/oauth/src/client.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ impl fmt::Debug for OAuth {
5555
}
5656

5757
impl OAuth {
58+
/// Create an OAuth client from a pre-existing access token.
59+
///
60+
/// This is useful for server-side scenarios where the token is obtained
61+
/// externally (e.g., via an MCP OAuth proxy) and you need to construct
62+
/// an [`OAuth`] instance without going through the browser authorization
63+
/// flow.
64+
///
65+
/// The returned instance does **not** support token refresh — calling
66+
/// [`access_token`](OAuth::access_token) simply returns the provided
67+
/// token until it expires.
68+
pub fn from_token(access_token: impl Into<String>) -> Self {
69+
let access_token = access_token.into();
70+
Self(Arc::new(OAuthInner {
71+
client_id: String::new(),
72+
callback_port: DEFAULT_CALLBACK_PORT,
73+
token: tokio::sync::Mutex::new(Some(OAuthToken {
74+
client_id: String::new(),
75+
access_token,
76+
refresh_token: None,
77+
expires_at: u64::MAX,
78+
})),
79+
}))
80+
}
81+
5882
/// Return the OAuth client ID
5983
pub fn client_id(&self) -> &str {
6084
&self.0.client_id

0 commit comments

Comments
 (0)