fix(backend): Fix ApiKeyId lookup in PendingChangeService
The PendingChangeService was looking for 'ApiKeyId' in HttpContext.Items, but McpApiKeyAuthenticationHandler sets 'McpApiKeyId'. Updated the lookup to check both keys for backward compatibility. Changes: - Modified ApiKeyId retrieval to check 'McpApiKeyId' first, then fall back to 'ApiKeyId' - Prevents McpUnauthorizedException: API Key not found in request context Fixes compatibility between McpApiKeyAuthenticationHandler and PendingChangeService. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,9 @@ public class PendingChangeService(
|
|||||||
var tenantId = _tenantContext.GetCurrentTenantId();
|
var tenantId = _tenantContext.GetCurrentTenantId();
|
||||||
|
|
||||||
// Get API Key ID from HttpContext (set by MCP authentication middleware)
|
// Get API Key ID from HttpContext (set by MCP authentication middleware)
|
||||||
var apiKeyIdNullable = _httpContextAccessor.HttpContext?.Items["ApiKeyId"] as Guid?;
|
// Check both "McpApiKeyId" (from McpApiKeyAuthenticationHandler) and "ApiKeyId" (from legacy middleware)
|
||||||
|
var apiKeyIdNullable = _httpContextAccessor.HttpContext?.Items["McpApiKeyId"] as Guid?
|
||||||
|
?? _httpContextAccessor.HttpContext?.Items["ApiKeyId"] as Guid?;
|
||||||
if (!apiKeyIdNullable.HasValue)
|
if (!apiKeyIdNullable.HasValue)
|
||||||
{
|
{
|
||||||
throw new McpUnauthorizedException("API Key not found in request context");
|
throw new McpUnauthorizedException("API Key not found in request context");
|
||||||
|
|||||||
Reference in New Issue
Block a user