feat: scope API MCP OAuth by principal

This commit is contained in:
wizardchen
2026-06-30 09:21:49 +08:00
committed by lyingbug
parent 77e4f93e3e
commit cb99736d72
39 changed files with 1566 additions and 108 deletions
+6 -6
View File
@@ -645,16 +645,16 @@ func (h *MCPServiceHandler) ResolveToolApproval(c *gin.Context) {
c.Error(errors.NewBadRequestError("decision must be approve or reject"))
return
}
userID, _ := c.Get(types.UserIDContextKey.String())
userIDStr, _ := userID.(string)
// Reject calls without an authenticated user up front. The gate's
// per-user authorization is fail-close, but surfacing 401 here gives
principal, _ := types.PrincipalFromContext(ctx)
gateUserID := principal.StorageID()
// Reject calls without an authenticated principal up front. The gate's
// per-principal authorization is fail-close, but surfacing 401 here gives
// a clearer signal that auth middleware did not populate the context.
if strings.TrimSpace(userIDStr) == "" {
if strings.TrimSpace(gateUserID) == "" {
c.Error(errors.NewUnauthorizedError("authenticated user required to resolve tool approval"))
return
}
if err := h.toolApprovalGate.Resolve(tenantID, userIDStr, pendingID, dec); err != nil {
if err := h.toolApprovalGate.Resolve(tenantID, gateUserID, pendingID, dec); err != nil {
switch {
case stderrors.Is(err, approval.ErrPendingNotFound):
c.Error(errors.NewNotFoundError("pending approval not found or already completed"))