mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-28 11:54:02 +08:00
feat/auth-hook: add post auth hook [CR]
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user