feat/auth-hook: add post auth hook [CR]

This commit is contained in:
HEUDavid
2026-02-10 22:11:41 +08:00
parent 6a9e3a6b84
commit 3caadac003
2 changed files with 20 additions and 5 deletions

View File

@@ -2286,19 +2286,19 @@ func PopulateAuthContext(ctx context.Context, c *gin.Context) context.Context {
Headers: make(map[string]string), 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() { for k, v := range c.Request.URL.Query() {
if len(v) > 0 { 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 { for k, v := range c.Request.Header {
if len(v) > 0 { 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)
} }

View File

@@ -25,6 +25,21 @@ type RequestInfo struct {
Headers map[string]string 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. // Auth encapsulates the runtime state and metadata associated with a single credential.
type Auth struct { type Auth struct {
// ID uniquely identifies the auth record across restarts. // ID uniquely identifies the auth record across restarts.