middleware

package
v1.19.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentSessionIDFromContext

func GetCurrentSessionIDFromContext(ctx context.Context) (string, bool)

GetCurrentSessionIDFromContext retrieves the current session ID from the context.

func GetCurrentUserFromContext

func GetCurrentUserFromContext(ctx context.Context) (*models.User, bool)

GetCurrentUserFromContext retrieves the current user from the context.

func GetRemoteAddrFromContext

func GetRemoteAddrFromContext(ctx context.Context) string

GetRemoteAddrFromContext retrieves the request remote address from context.

func GetUserIDFromContext

func GetUserIDFromContext(ctx context.Context) (string, bool)

GetUserIDFromContext retrieves the user ID from the context.

func IsAdminFromContext

func IsAdminFromContext(ctx context.Context) bool

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL