Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(mcp): handle upstream oauth errors in callback (#2865)
Eric Hayesa80c9d3efa1f
diff --git a/infra/stacks/fusionauth-instance/origins.ts b/infra/stacks/fusionauth-instance/origins.tsindex 390bc71411..66d4535187 100644--- a/infra/stacks/fusionauth-instance/origins.ts+++ b/infra/stacks/fusionauth-instance/origins.ts@@ -22,6 +22,9 @@ export const ALLOWED_ORIGINS = () => {'http://localhost:3009','http://localhost:5173','https://github.com',+ 'https://claude.ai',+ 'https://chatgpt.com',+ 'https://chat.openai.com',];case 'dev':return [@@ -41,6 +44,9 @@ export const ALLOWED_ORIGINS = () => {'http://localhost:5173','https://dashboarddev.macro.com','https://github.com',+ 'https://claude.ai',+ 'https://chatgpt.com',+ 'https://chat.openai.com',];case 'prod':return [@@ -51,6 +57,9 @@ export const ALLOWED_ORIGINS = () => {'https://www.macro.com','https://pdf.macro.com','https://github.com',+ 'https://claude.ai',+ 'https://chatgpt.com',+ 'https://chat.openai.com',];}diff --git a/rust/cloud-storage/mcp_auth_proxy/src/domain/models.rs b/rust/cloud-storage/mcp_auth_proxy/src/domain/models.rsindex bcbeef45a2..04a7a67682 100644--- a/rust/cloud-storage/mcp_auth_proxy/src/domain/models.rs+++ b/rust/cloud-storage/mcp_auth_proxy/src/domain/models.rs@@ -135,10 +135,18 @@ pub struct AuthorizeRequest {/// OAuth callback request from the upstream auth server.#[derive(Deserialize)]pub struct CallbackRequest {- /// Authorization code from the upstream auth server.- pub code: String,+ /// Authorization code from the upstream auth server. Absent when the+ /// upstream returned an error response instead of granting a code.+ #[serde(default)]+ pub code: Option<String>,/// Broker session ID threaded through the upstream `state`.pub state: Option<String>,+ /// OAuth error code when the upstream signals a failure.+ #[serde(default)]+ pub error: Option<String>,+ /// Human-readable error description from the upstream.+ #[serde(default)]+ pub error_description: Option<String>,}/// OAuth token request from the MCP client.diff --git a/rust/cloud-storage/mcp_auth_proxy/src/domain/service.rs b/rust/cloud-storage/mcp_auth_proxy/src/domain/service.rsindex c6b7b2301f..42da0ce16e 100644--- a/rust/cloud-storage/mcp_auth_proxy/src/domain/service.rs+++ b/rust/cloud-storage/mcp_auth_proxy/src/domain/service.rs@@ -282,9 +282,33 @@ where.map_err(CompleteCallbackError::InflightStore)?.ok_or(CompleteCallbackError::UnknownOrExpiredSession)?;+ if let Some(error) = params.error {+ tracing::warn!(+ %session_id,+ %error,+ description = ?params.error_description,+ "upstream oauth returned error"+ );+ let mut redirect = format!(+ "{}?error={}&state={}",+ pending.client_redirect_uri,+ urlencoding::encode(&error),+ urlencoding::encode(&pending.client_state),+ );+ if let Some(desc) = params.error_description {+ redirect.push_str(&format!(+ "&error_description={}",+ urlencoding::encode(&desc)+ ));+ }+ return Ok(redirect);+ }++ let code = params.code.ok_or(CompleteCallbackError::MissingCode)?;+let (access_token, refresh_token) = self.oauth_provider- .exchange_authorization_code(¶ms.code)+ .exchange_authorization_code(&code).await.map_err(CompleteCallbackError::AuthorizationCodeExchangeFailed)?;@@ -371,6 +395,9 @@ pub enum CompleteCallbackError {/// Upstream callback omitted state.#[error("missing state parameter")]MissingState,+ /// Upstream callback omitted both the authorization code and an error code.+ #[error("missing code parameter")]+ MissingCode,/// Pending broker session was missing or expired.#[error("unknown or expired session")]UnknownOrExpiredSession,diff --git a/rust/cloud-storage/mcp_auth_proxy/src/inbound/axum_router.rs b/rust/cloud-storage/mcp_auth_proxy/src/inbound/axum_router.rsindex 34fb7dbb42..88ddbd1b76 100644--- a/rust/cloud-storage/mcp_auth_proxy/src/inbound/axum_router.rs+++ b/rust/cloud-storage/mcp_auth_proxy/src/inbound/axum_router.rs@@ -99,6 +99,14 @@ async fn oauth_callback<I: InflightAuthStore + 'static>().into_response()}+ Err(CompleteCallbackError::MissingCode) => {+ tracing::warn!("upstream OAuth callback missing both code and error");+ (+ axum::http::StatusCode::BAD_REQUEST,+ "missing code parameter",+ )+ .into_response()+ }Err(CompleteCallbackError::UnknownOrExpiredSession) => (axum::http::StatusCode::BAD_REQUEST,"unknown or expired session",