pub trait UpstreamSignIn:
Send
+ Sync
+ 'static {
// Required methods
fn provider(&self) -> &str;
fn authorize_url(&self, redirect_uri: &str, state: &str) -> String;
fn exchange<'a>(
&'a self,
code: &'a str,
redirect_uri: &'a str,
) -> ExchangeFuture<'a>;
}Expand description
The upstream provider’s side of the sign-in: where to send people and how to turn the code the provider sends back into a credential.
use mcp_server_core::upstream::{Exchange, ExchangeFuture, UpstreamGrant, UpstreamSignIn};
struct Example;
impl UpstreamSignIn for Example {
fn provider(&self) -> &str {
"Example"
}
fn authorize_url(&self, redirect_uri: &str, state: &str) -> String {
let mut url = url::Url::parse("https://example.com/oauth/authorize").unwrap();
url.query_pairs_mut()
.append_pair("response_type", "code")
.append_pair("client_id", "my-client-id")
.append_pair("redirect_uri", redirect_uri)
.append_pair("state", state);
url.into()
}
fn exchange<'a>(&'a self, code: &'a str, _redirect_uri: &'a str) -> ExchangeFuture<'a> {
Box::pin(async move {
// POST the code to the provider's token endpoint here.
Exchange::Granted(UpstreamGrant::new(format!("refresh-token-for-{code}")))
})
}
}Required Methods§
Sourcefn provider(&self) -> &str
fn provider(&self) -> &str
The provider’s name as it reads in a sentence, e.g. “FreeAgent”: the sign-in page’s button says “Continue to FreeAgent”.
The provider’s authorization URL for this sign-in: its authorization endpoint with at least
response_type=code, the server’s OAuth client id, redirect_uri and state, each passed
on exactly as given. redirect_uri is PUBLIC_URL/callback.
Sourcefn exchange<'a>(
&'a self,
code: &'a str,
redirect_uri: &'a str,
) -> ExchangeFuture<'a>
fn exchange<'a>( &'a self, code: &'a str, redirect_uri: &'a str, ) -> ExchangeFuture<'a>
Exchanges the authorization code the provider sent back, at its token endpoint, sending
the same redirect_uri. Runs with a timeout.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".