From 3caadac0033a5f869ce5554d7d4b5ef5a7b359ee Mon Sep 17 00:00:00 2001 From: HEUDavid Date: Tue, 10 Feb 2026 22:11:41 +0800 Subject: [PATCH] feat/auth-hook: add post auth hook [CR] --- internal/api/handlers/management/auth_files.go | 10 +++++----- sdk/cliproxy/auth/types.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/internal/api/handlers/management/auth_files.go b/internal/api/handlers/management/auth_files.go index 38004794..5d4e98ec 100644 --- a/internal/api/handlers/management/auth_files.go +++ b/internal/api/handlers/management/auth_files.go @@ -2286,19 +2286,19 @@ func PopulateAuthContext(ctx context.Context, c *gin.Context) context.Context { Headers: make(map[string]string), } - // Capture all query parameters + // Capture all query parameters, joining multiple values with a comma. for k, v := range c.Request.URL.Query() { if len(v) > 0 { - info.Query[k] = v[0] + info.Query[k] = strings.Join(v, ",") } } - // Capture all headers + // Capture all headers, joining multiple values with a comma. for k, v := range c.Request.Header { if len(v) > 0 { - info.Headers[k] = v[0] + info.Headers[k] = strings.Join(v, ",") } } - return context.WithValue(ctx, "request_info", info) + return coreauth.WithRequestInfo(ctx, info) } diff --git a/sdk/cliproxy/auth/types.go b/sdk/cliproxy/auth/types.go index e1ba6bb5..29b4a560 100644 --- a/sdk/cliproxy/auth/types.go +++ b/sdk/cliproxy/auth/types.go @@ -25,6 +25,21 @@ type RequestInfo struct { Headers map[string]string } +type requestInfoKey struct{} + +// WithRequestInfo returns a new context with the given RequestInfo attached. +func WithRequestInfo(ctx context.Context, info *RequestInfo) context.Context { + return context.WithValue(ctx, requestInfoKey{}, info) +} + +// GetRequestInfo retrieves the RequestInfo from the context, if present. +func GetRequestInfo(ctx context.Context) *RequestInfo { + if val, ok := ctx.Value(requestInfoKey{}).(*RequestInfo); ok { + return val + } + return nil +} + // Auth encapsulates the runtime state and metadata associated with a single credential. type Auth struct { // ID uniquely identifies the auth record across restarts.