feat(embed): scope OAuth and sessions per visitor principal
Add embed visitor principals (X-Embed-Visitor), widen sessions.user_id, embed MCP OAuth/approval routes, OAuth callback context detachment, and CloneContext principal preservation for async QA streams.
This commit is contained in:
@@ -499,6 +499,7 @@ func CloneContext(ctx context.Context) context.Context {
|
||||
types.TenantInfoContextKey,
|
||||
types.UserIDContextKey,
|
||||
types.UserContextKey,
|
||||
types.PrincipalContextKey,
|
||||
// TenantRoleContextKey: the caller's resolved role in the
|
||||
// active tenant (PR 2 #1303). Must be propagated for the same
|
||||
// reason as TenantIDContextKey — any handler that does
|
||||
@@ -510,6 +511,7 @@ func CloneContext(ctx context.Context) context.Context {
|
||||
types.LanguageContextKey,
|
||||
types.SessionTenantIDContextKey,
|
||||
types.EmbedQueryContextKey,
|
||||
types.EmbedVisitorContextKey,
|
||||
// Keep the Langfuse trace alive across CloneContext boundaries so
|
||||
// LLM/Embedder/Reranker/VLM/ASR wrappers attach their generations
|
||||
// to the same trace opened by GinMiddleware, instead of each call
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -164,3 +166,14 @@ func TestLevelColorFor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloneContextPreservesPrincipal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := types.WithPrincipal(context.Background(), types.EmbedSessionPrincipal(10000, "ch1", "sess1"))
|
||||
cloned := CloneContext(ctx)
|
||||
|
||||
if got := types.SessionOwnerIDFromContext(cloned); got != "embed_session:10000:ch1:sess1" {
|
||||
t.Fatalf("SessionOwnerIDFromContext(cloned) = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user