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 ¶
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 ¶
RequireAuth is a middleware that requires authentication. Returns 401 Unauthorized if no valid token is present.
Types ¶
type AuthenticatedUser ¶
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.
Click to show internal directories.
Click to hide internal directories.