mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Require a client ID for config server OAuth discovery (#65200)
## Why Config server OAuth discovery falls back to `codex` when no client ID is configured. That can select the wrong client for the server. ## What changed When discovery finds OAuth metadata but no client ID is configured, return an error that points to `gateway.auth.client_id` and `config_server.oauth.client_id` in `requirements.toml`. ## Testing Cover missing client IDs both with and without discovery overrides, and verify that an explicitly configured `codex` client ID still works. GitOrigin-RevId: 26e7f7176dcc2ea6aa71bd3b0bc9b0dbf5bf7fbb
This commit is contained in:
committed by
copyberry
parent
986dc881be
commit
d62166e0c8
@@ -80,6 +80,12 @@ async fn resolve_oauth(
|
||||
return Ok(None);
|
||||
};
|
||||
let overrides = overrides.cloned().unwrap_or_default();
|
||||
let client_id = overrides.client_id.ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"OAuth discovery requires a client ID. Set gateway.auth.client_id or config_server.oauth.client_id in requirements.toml.",
|
||||
)
|
||||
})?;
|
||||
let device_authorization_url = match overrides.device_authorization_url {
|
||||
Some(url) => Some(url),
|
||||
None => metadata
|
||||
@@ -95,7 +101,7 @@ async fn resolve_oauth(
|
||||
authorization_url: metadata.authorization_endpoint,
|
||||
token_url: metadata.token_endpoint,
|
||||
device_authorization_url,
|
||||
client_id: overrides.client_id.unwrap_or_else(|| String::from("codex")),
|
||||
client_id,
|
||||
resource: overrides.resource,
|
||||
scopes: overrides.scopes,
|
||||
redirect_port: overrides.redirect_port,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg(test)]
|
||||
|
||||
//! Tests config-server OAuth defaults, discovery activation, and routing.
|
||||
//! Tests config-server OAuth discovery, client settings, and routing.
|
||||
|
||||
use super::DISCOVERY_TIMEOUT;
|
||||
use super::resolve_config_server;
|
||||
@@ -31,8 +31,15 @@ fn metadata(issuer: &str) -> Value {
|
||||
})
|
||||
}
|
||||
|
||||
fn client_id_only() -> ConfigServerOAuth {
|
||||
ConfigServerOAuth::Discover(OAuthDiscoveryOverrides {
|
||||
client_id: Some("codex".into()),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn applies_company_defaults_and_optional_device_endpoint() {
|
||||
async fn preserves_explicit_codex_client_id_and_optional_device_endpoint() {
|
||||
let server = MockServer::start().await;
|
||||
for device_url in [None, Some("https://login.example/device")] {
|
||||
server.reset().await;
|
||||
@@ -56,7 +63,7 @@ async fn applies_company_defaults_and_optional_device_endpoint() {
|
||||
resolve_oauth(
|
||||
&server.uri(),
|
||||
&transport_default_auth_route_config(),
|
||||
/*configured*/ None
|
||||
Some(&client_id_only())
|
||||
)
|
||||
.await
|
||||
.unwrap(),
|
||||
@@ -108,11 +115,18 @@ async fn discovers_endpoints_and_uses_configured_scopes() {
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(metadata(&server.uri())))
|
||||
.mount(&server)
|
||||
.await;
|
||||
let default_session = resolve_oauth(&server.uri(), &routes, /*configured*/ None)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(default_session.scopes.is_empty());
|
||||
let scopes_only = ConfigServerOAuth::Discover(OAuthDiscoveryOverrides {
|
||||
scopes: vec!["read".into()],
|
||||
..Default::default()
|
||||
});
|
||||
for missing_id in [None, Some(&scopes_only)] {
|
||||
let error = resolve_oauth(&server.uri(), &routes, missing_id)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||||
assert!(error.to_string().contains("gateway.auth.client_id"));
|
||||
assert!(error.to_string().contains("config_server.oauth.client_id"));
|
||||
}
|
||||
let session = resolve_oauth(&server.uri(), &routes, Some(&configured))
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -136,7 +150,7 @@ async fn rejects_invalid_device_endpoint() {
|
||||
let error = resolve_oauth(
|
||||
&server.uri(),
|
||||
&transport_default_auth_route_config(),
|
||||
/*configured*/ None,
|
||||
Some(&client_id_only()),
|
||||
)
|
||||
.await
|
||||
.unwrap_err();
|
||||
@@ -226,7 +240,7 @@ async fn discovery_obeys_local_network_policy_without_requiring_fetched_policy()
|
||||
.mount(&server)
|
||||
.await;
|
||||
assert!(
|
||||
resolve_oauth(&server.uri(), &routes, /*configured*/ None)
|
||||
resolve_oauth(&server.uri(), &routes, Some(&client_id_only()))
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some()
|
||||
@@ -236,7 +250,7 @@ async fn discovery_obeys_local_network_policy_without_requiring_fetched_policy()
|
||||
let routes =
|
||||
AuthRouteConfig::from_http_client_factory(allowed).with_local_bootstrap_factory(blocked);
|
||||
assert!(
|
||||
resolve_oauth(&server.uri(), &routes, /*configured*/ None)
|
||||
resolve_oauth(&server.uri(), &routes, Some(&client_id_only()))
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user