fix(backend): Use tenant_id claim name in MCP API Key authentication

Fixed TenantId claim name mismatch between McpApiKeyAuthenticationHandler
and ITenantContext implementations. Changed claim name from "TenantId" to
"tenant_id" to match what TenantContext.GetCurrentTenantId() expects.

This fixes the "TenantId cannot be empty" error when MCP SDK Resources
attempt to retrieve the tenant ID after API Key authentication.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2025-11-23 15:32:04 +01:00
parent b38a9d16fa
commit a55006b810

View File

@@ -48,11 +48,12 @@ public class McpApiKeyAuthenticationHandler : AuthenticationHandler<McpApiKeyAut
}
// Create claims from validation result
// Note: Use "tenant_id" to match ITenantContext implementations that look for this claim name
var claims = new List<Claim>
{
new(ClaimTypes.NameIdentifier, validationResult.UserId.ToString()),
new("ApiKeyId", validationResult.ApiKeyId.ToString()),
new("TenantId", validationResult.TenantId.ToString()),
new("tenant_id", validationResult.TenantId.ToString()),
new("UserId", validationResult.UserId.ToString()),
};