docs: explain OAuth HTTP client setup (#918)

This commit is contained in:
Dale Seo 2026-06-25 19:59:47 -04:00 • committed by GitHub
commit f1daa9277e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 140 additions and 51 deletions

View file

@ -45,6 +45,7 @@ A client demonstrating how to authenticate with an MCP server using OAuth.
- Starts a local HTTP server to handle OAuth callbacks
- Initializes the OAuth state machine and begins the authorization flow
- Shows how to pass a configured reqwest client for OAuth discovery, registration, token exchange, and refresh requests
- Displays the authorization URL and waits for user authorization
- Establishes an authorized connection to the MCP server using the acquired access token
- Demonstrates how to use the authorized connection to retrieve available tools and prompts

View file

@ -1,4 +1,4 @@
use std::{env, net::SocketAddr, sync::Arc};
use std::{env, net::SocketAddr, sync::Arc, time::Duration};
use anyhow::{Context, Result};
use axum::{
@ -115,8 +115,16 @@ async fn main() -> Result<()> {
client_metadata_url
);
// Configure the HTTP client used for OAuth discovery, registration, token
// exchange, and refresh. Customize this builder for proxies, TLS roots,
// default headers, or other reqwest settings required by your environment.
let oauth_http_client = reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.build()
.context("Failed to build OAuth HTTP client")?;
// initialize oauth state machine
let mut oauth_state = OAuthState::new(&server_url, None)
let mut oauth_state = OAuthState::new(&server_url, Some(oauth_http_client))
.await
.context("Failed to initialize oauth state machine")?;
// use CIMD (SEP-991) with client metadata URL.