Documentation
¶
Index ¶
- func GetCurrentSessionIDFromContext(ctx context.Context) (string, bool)
- func GetCurrentUserFromContext(ctx context.Context) (*models.User, bool)
- func GetRemoteAddrFromContext(ctx context.Context) string
- func GetUserIDFromContext(ctx context.Context) (string, bool)
- func IsAdminFromContext(ctx context.Context) bool
- func NewAuthBridge(api huma.API, authService *services.AuthService, ...) func(ctx huma.Context, next func(huma.Context))
- func RequireAdmin(api huma.API) huma.Middlewares
- type ContextKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCurrentSessionIDFromContext ¶
GetCurrentSessionIDFromContext retrieves the current session ID from the context.
func GetCurrentUserFromContext ¶
GetCurrentUserFromContext retrieves the current user from the context.
func GetRemoteAddrFromContext ¶
GetRemoteAddrFromContext retrieves the request remote address from context.
func GetUserIDFromContext ¶
GetUserIDFromContext retrieves the user ID from the context.
func IsAdminFromContext ¶
IsAdminFromContext checks if the current user is an admin.
func NewAuthBridge ¶
func NewAuthBridge(api huma.API, authService *services.AuthService, apiKeyService *services.ApiKeyService, envTokenResolver environmentAccessTokenResolver, cfg *config.Config) func(ctx huma.Context, next func(huma.Context))
NewAuthBridge creates a Huma middleware that validates JWT tokens and enforces security requirements defined on operations.
func RequireAdmin ¶ added in v1.19.2
func RequireAdmin(api huma.API) huma.Middlewares
RequireAdmin returns a per-operation Huma middleware slice that returns 403 to non-admin callers. Attach via Operation.Middlewares:
huma.Register(api, huma.Operation{..., Middlewares: middleware.RequireAdmin(api)}, h.Handler)
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is a type for context keys used by Huma handlers.
const ( // ContextKeyUserID is the context key for the authenticated user's ID. ContextKeyUserID ContextKey = "userID" // ContextKeyCurrentUser is the context key for the authenticated user model. ContextKeyCurrentUser ContextKey = "currentUser" // ContextKeyCurrentSessionID is the context key for the authenticated session ID. ContextKeyCurrentSessionID ContextKey = "currentSessionID" // ContextKeyUserIsAdmin is the context key for whether the user is an admin. ContextKeyUserIsAdmin ContextKey = "userIsAdmin" // ContextKeyRemoteAddr is the context key for the request remote address. ContextKeyRemoteAddr ContextKey = "remoteAddr" )