mirror of
https://github.com/openai/codex.git
synced 2026-10-30 19:18:49 +00:00
Add explicit gateway OAuth sign-in to app-server (#47207)
## Why Clients with a gateway sign-in UI need to control when browser authorization starts and inspect credential readiness before making authenticated requests. ## What changed - Add `initialize.capabilities.explicitGatewayOauth` to require explicit login while allowing existing credentials to refresh. Preserve automatic authorization for clients that omit the capability, and prevent later connections from undoing explicit opt-in. - Add `account/gatewayOAuth/read`, `account/gatewayOAuth/login`, and `account/gatewayOAuth/cancel`, plus `account/gatewayOAuth/changed` notifications. Send the authorization URL only to the initiating connection and cancel its login on disconnect. - Check gateway authentication before returning cached results from `model/list`, with restart guidance when provider settings have changed. - Update protocol schemas, TypeScript and Python bindings, and document capability probing and the sign-in lifecycle. ## Testing Add tests for passive readiness reads, credential reuse after login, token exchange failures, cancellation and immediate retry, connection ownership, legacy versus explicit login, and model-list authentication checks. GitOrigin-RevId: a26e116a62c9f3db84dc238a40b7f4e816eb1594
This commit is contained in:
@@ -290,6 +290,10 @@ impl MessageProcessor {
|
||||
remote_control_handle,
|
||||
plugin_startup_tasks,
|
||||
} = args;
|
||||
// Startup credential reads must not open a browser before initialize selects the policy.
|
||||
let gateway_login_control =
|
||||
codex_login::GatewayLoginControl::for_runtime(&auth_manager.runtime_config());
|
||||
gateway_login_control.require_explicit_login();
|
||||
let thread_state_manager = ThreadStateManager::new();
|
||||
outgoing.watch_user_verification_auth(Arc::clone(&auth_manager));
|
||||
// The thread store is intentionally process-scoped. Config reloads can
|
||||
@@ -450,6 +454,7 @@ impl MessageProcessor {
|
||||
);
|
||||
let git_processor = GitRequestProcessor::new();
|
||||
let initialize_processor = InitializeRequestProcessor::new(
|
||||
gateway_login_control,
|
||||
outgoing.clone(),
|
||||
analytics_events_client.clone(),
|
||||
Arc::clone(&config),
|
||||
@@ -862,6 +867,8 @@ impl MessageProcessor {
|
||||
session_state: &ConnectionSessionState,
|
||||
) {
|
||||
session_state.rpc_gate.close().await;
|
||||
self.account_processor
|
||||
.gateway_connection_closed(connection_id);
|
||||
self.request_serialization_queues.discard_closed().await;
|
||||
self.outgoing
|
||||
.disconnect_user_verification_connection(connection_id)
|
||||
@@ -1730,6 +1737,33 @@ impl MessageProcessor {
|
||||
ClientRequest::BedrockSetup { params, .. } => {
|
||||
self.account_processor.bedrock_setup(params).await
|
||||
}
|
||||
ClientRequest::GatewayOAuthRead { .. } => {
|
||||
Box::pin(self.account_processor.gateway_oauth_read())
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
}
|
||||
ClientRequest::GatewayOAuthLogin { .. } => {
|
||||
if session
|
||||
.opted_out_notification_methods()
|
||||
.contains("account/gatewayOAuth/changed")
|
||||
{
|
||||
Err(invalid_request(
|
||||
"Gateway login requires account/gatewayOAuth/changed notifications",
|
||||
))
|
||||
} else {
|
||||
Box::pin(
|
||||
self.account_processor
|
||||
.gateway_oauth_login(connection_id, &session.rpc_gate),
|
||||
)
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
}
|
||||
}
|
||||
ClientRequest::GatewayOAuthCancel { .. } => {
|
||||
Box::pin(self.account_processor.gateway_oauth_cancel(connection_id))
|
||||
.await
|
||||
.map(|response| Some(response.into()))
|
||||
}
|
||||
ClientRequest::LogoutAccount { .. } => {
|
||||
self.account_processor
|
||||
.logout_account(request_id.clone())
|
||||
@@ -1849,3 +1883,7 @@ impl MessageProcessor {
|
||||
#[cfg(test)]
|
||||
#[path = "message_processor_tracing_tests.rs"]
|
||||
mod message_processor_tracing_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "message_processor_gateway_oauth_tests.rs"]
|
||||
mod gateway_oauth_tests;
|
||||
|
||||
Reference in New Issue
Block a user