mirror of
https://github.com/openai/codex.git
synced 2026-11-23 07:17:11 +00:00
Use configured HTTP clients for all MCP OAuth requests (#35814)
## What changed - Require callers to provide an HTTP client for MCP OAuth discovery and login, removing the separate direct `reqwest` path. - Use the shared `http` and `url` types throughout the MCP client and drop its direct `reqwest` dependency. - Preserve configured MCP headers when routing OAuth discovery through the provided client. ## Testing - Add coverage that routed OAuth discovery forwards configured headers. GitOrigin-RevId: 1345f56bd794626533133447597a5908e57b9b48
This commit is contained in:
1 parent
9ea975a2dc
commit
709283b432
25 files changed
+181
-380
No files matched your search
@@ -12,9 +12,8 @@ use codex_login::CodexAuth;
|
||||
use codex_rmcp_client::McpAuthState;
|
||||
use codex_rmcp_client::OAuthDiscoveryTimeout;
|
||||
use codex_rmcp_client::OAuthProviderError;
|
||||
use codex_rmcp_client::determine_streamable_http_auth_status_with_http_client;
|
||||
use codex_rmcp_client::determine_streamable_http_auth_status;
|
||||
use codex_rmcp_client::discover_streamable_http_oauth;
|
||||
use codex_rmcp_client::discover_streamable_http_oauth_with_http_client;
|
||||
use futures::FutureExt;
|
||||
use futures::future::join_all;
|
||||
use tracing::warn;
|
||||
@@ -57,27 +56,7 @@ pub struct McpAuthStatusEntry {
|
||||
pub auth_state: McpAuthState,
|
||||
}
|
||||
|
||||
pub async fn oauth_login_support(transport: &McpServerTransportConfig) -> McpOAuthLoginSupport {
|
||||
let Some(mut config) = oauth_login_candidate(transport) else {
|
||||
return McpOAuthLoginSupport::Unsupported;
|
||||
};
|
||||
match discover_streamable_http_oauth(
|
||||
&config.url,
|
||||
config.http_headers.clone(),
|
||||
config.env_http_headers.clone(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Some(discovery)) => {
|
||||
config.discovered_scopes = discovery.scopes_supported;
|
||||
McpOAuthLoginSupport::Supported(config)
|
||||
}
|
||||
Ok(None) => McpOAuthLoginSupport::Unsupported,
|
||||
Err(err) => McpOAuthLoginSupport::Unknown(err),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn oauth_login_support_with_http_client(
|
||||
pub async fn oauth_login_support(
|
||||
transport: &McpServerTransportConfig,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
discovery_timeout: OAuthDiscoveryTimeout,
|
||||
@@ -85,7 +64,7 @@ pub async fn oauth_login_support_with_http_client(
|
||||
let Some(mut config) = oauth_login_candidate(transport) else {
|
||||
return McpOAuthLoginSupport::Unsupported;
|
||||
};
|
||||
match discover_streamable_http_oauth_with_http_client(
|
||||
match discover_streamable_http_oauth(
|
||||
&config.url,
|
||||
config.http_headers.clone(),
|
||||
config.env_http_headers.clone(),
|
||||
@@ -126,19 +105,10 @@ fn oauth_login_candidate(transport: &McpServerTransportConfig) -> Option<McpOAut
|
||||
|
||||
pub async fn discover_supported_scopes(
|
||||
transport: &McpServerTransportConfig,
|
||||
) -> Option<Vec<String>> {
|
||||
match oauth_login_support(transport).await {
|
||||
McpOAuthLoginSupport::Supported(config) => config.discovered_scopes,
|
||||
McpOAuthLoginSupport::Unsupported | McpOAuthLoginSupport::Unknown(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn discover_supported_scopes_with_http_client(
|
||||
transport: &McpServerTransportConfig,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
discovery_timeout: OAuthDiscoveryTimeout,
|
||||
) -> Option<Vec<String>> {
|
||||
match oauth_login_support_with_http_client(transport, http_client, discovery_timeout).await {
|
||||
match oauth_login_support(transport, http_client, discovery_timeout).await {
|
||||
McpOAuthLoginSupport::Supported(config) => config.discovered_scopes,
|
||||
McpOAuthLoginSupport::Unsupported | McpOAuthLoginSupport::Unknown(_) => None,
|
||||
}
|
||||
@@ -266,7 +236,7 @@ async fn compute_auth_status(
|
||||
} else {
|
||||
OAuthDiscoveryTimeout::Requested
|
||||
};
|
||||
determine_streamable_http_auth_status_with_http_client(
|
||||
determine_streamable_http_auth_status(
|
||||
server_name,
|
||||
url,
|
||||
bearer_token_env_var.as_deref(),
|
||||
|
||||
@@ -5,9 +5,7 @@ pub use auth::McpOAuthScopesSource;
|
||||
pub use auth::ResolvedMcpOAuthScopes;
|
||||
pub use auth::compute_auth_statuses;
|
||||
pub use auth::discover_supported_scopes;
|
||||
pub use auth::discover_supported_scopes_with_http_client;
|
||||
pub use auth::oauth_login_support;
|
||||
pub use auth::oauth_login_support_with_http_client;
|
||||
pub use auth::resolve_oauth_scopes;
|
||||
pub use auth::should_retry_without_scopes;
|
||||
|
||||
|
||||
Reference in new issue
Block a user