Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go/adk/pkg/a2a/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (u *userIDInterceptor) Before(ctx context.Context, callCtx *a2asrv.CallCont
}
// Set the authenticated user so downstream code picks up the real identity.
callCtx.User = a2asrv.NewAuthenticatedUser(vals[0], nil)
return ctx, nil, nil
return auth.WithUserID(ctx, vals[0]), nil, nil
}

// Execute applies kagent-specific request setup and delegates event generation
Expand All @@ -114,8 +114,8 @@ func (e *KAgentExecutor) Execute(ctx context.Context, reqCtx *a2asrv.ExecutorCon
}

userID := "A2A_USER_" + reqCtx.ContextID
if callCtx, ok := a2asrv.CallContextFrom(ctx); ok && callCtx.User != nil && callCtx.User.Name != "" {
userID = callCtx.User.Name
if id := auth.UserIDFromContext(ctx); id != "" {
userID = id
}
sessionID := reqCtx.ContextID

Expand Down
19 changes: 19 additions & 0 deletions go/adk/pkg/a2a/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
a2atype "github.com/a2aproject/a2a-go/v2/a2a"
"github.com/a2aproject/a2a-go/v2/a2asrv"
"github.com/go-logr/logr"
"github.com/kagent-dev/kagent/go/adk/pkg/auth"
adkagent "google.golang.org/adk/v2/agent"
"google.golang.org/adk/v2/model"
"google.golang.org/adk/v2/runner"
Expand Down Expand Up @@ -126,6 +127,24 @@ func TestKAgentExecutor_ForwardsCleanup(t *testing.T) {
}
}

func TestUserIDCallInterceptor_SetsCtxUserID(t *testing.T) {
ctx, callCtx := a2asrv.NewCallContext(context.Background(), a2asrv.NewServiceParams(map[string][]string{
"x-user-id": {"real-user"},
}))

returned, _, err := UserIDCallInterceptor().Before(ctx, callCtx, &a2asrv.Request{})
if err != nil {
t.Fatalf("Before() error = %v", err)
}

if got := callCtx.User.Name; got != "real-user" {
t.Fatalf("callCtx.User.Name = %q, want %q", got, "real-user")
}
if got := auth.UserIDFromContext(returned); got != "real-user" {
t.Fatalf("auth.UserIDFromContext(returned) = %q, want %q", got, "real-user")
}
}

func TestKAgentExecutor_TranslatesADKPauseAtA2ABoundary(t *testing.T) {
reqCtx := &a2asrv.ExecutorContext{
TaskID: "task-1", ContextID: "ctx-1",
Expand Down
Loading