llm/oauth/handler.rs
1use super::error::OAuthError;
2use futures::future::BoxFuture;
3
4/// OAuth callback data containing both the authorization code and state (CSRF token)
5#[derive(Debug, Clone)]
6pub struct OAuthCallback {
7 pub code: String,
8 pub state: String,
9}
10
11/// Trait that consuming applications implement to handle OAuth UI/UX.
12///
13/// Uses `BoxFuture` instead of `async fn` to support `dyn OAuthHandler`
14/// (required for `Arc<dyn OAuthHandler>` in `McpManager`).
15pub trait OAuthHandler: Send + Sync {
16 /// The redirect URI the OAuth provider should send the user back to,
17 /// e.g. `http://127.0.0.1:<port>/oauth2callback`.
18 fn redirect_uri(&self) -> &str;
19
20 /// Called when user needs to authorize. App should open browser to `auth_url`
21 /// and return the authorization code and state (CSRF token) from the callback.
22 fn authorize(&self, auth_url: &str) -> BoxFuture<'_, Result<OAuthCallback, OAuthError>>;
23}