Files
httpauth/auth.go

26 lines
804 B
Go
Raw Permalink Normal View History

package httpauth
import "context"
type ctxUIDKey struct{}
type ctxClaimsKey struct{}
// SetTokenData injects a verified uid and raw claims into the context.
// Called by provider-specific AuthMiddleware implementations after token verification.
// EnrichmentMiddleware reads these values automatically via unexported helpers.
func SetTokenData(ctx context.Context, uid string, claims map[string]any) context.Context {
ctx = context.WithValue(ctx, ctxUIDKey{}, uid)
ctx = context.WithValue(ctx, ctxClaimsKey{}, claims)
return ctx
}
func getUID(ctx context.Context) (string, bool) {
uid, ok := ctx.Value(ctxUIDKey{}).(string)
return uid, ok && uid != ""
}
func getClaims(ctx context.Context) (map[string]any, bool) {
claims, ok := ctx.Value(ctxClaimsKey{}).(map[string]any)
return claims, ok
}