middleware

package
v0.23.30 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for authentication.

Index

Constants

View Source
const (
	// UserContextKey is the context key for the authenticated user.
	UserContextKey contextKey = "authenticated_user"
)

Variables

This section is empty.

Functions

func BearerAuth

func BearerAuth(jwtService *jwt.Service) func(http.Handler) http.Handler

BearerAuth creates an authentication middleware that extracts JWT from Bearer token. It adds the authenticated user to the request context if a valid token is present. Requests without a token or with an invalid token continue without user context.

func RequireAuth

func RequireAuth(next http.Handler) http.Handler

RequireAuth is a middleware that requires authentication. Returns 401 Unauthorized if no valid token is present.

func RequirePlatformAdmin

func RequirePlatformAdmin(next http.Handler) http.Handler

RequirePlatformAdmin is a middleware that requires platform admin access. Returns 403 Forbidden if the user is not a platform admin.

Types

type AuthenticatedUser

type AuthenticatedUser struct {
	ID              uuid.UUID
	Email           string
	IsPlatformAdmin bool
}

AuthenticatedUser represents the authenticated user in the request context.

func UserFromContext

func UserFromContext(ctx context.Context) *AuthenticatedUser

UserFromContext extracts the authenticated user from the context.

Jump to

Keyboard shortcuts

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