middleware

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyAuthN added in v0.0.11

func APIKeyAuthN(authenticator KeyAuthenticator) func(http.HandlerFunc) http.HandlerFunc

func AuthN

func AuthN(authenticator Authenticator) func(http.HandlerFunc) http.HandlerFunc

AuthN returns an HTTP middleware that authenticates either a locally issued bearer token or an API key supplied via X-API-Key. If any check fails, a 401 Unauthorized response is returned.

func KeyFromContext added in v0.0.11

func KeyFromContext(ctx context.Context) *schema.Key

KeyFromContext returns the authenticated API key stored by the auth middleware.

func NewAPIKeyAuth added in v0.0.11

func NewAPIKeyAuth(authenticator KeyAuthenticator) *apiKeyAuth

func NewBearerAuth

func NewBearerAuth(authenticator Authenticator) *bearerAuth

func SessionFromContext

func SessionFromContext(ctx context.Context) *schema.Session

SessionFromContext returns the authenticated session stored by the auth middleware.

func UserFromContext

func UserFromContext(ctx context.Context) *schema.UserInfo

UserFromContext returns the authenticated user stored by the auth middleware.

Types

type Authenticator added in v0.0.11

type Authenticator interface {
	Issuer() (string, error)
	AuthenticateBearer(ctx context.Context, token string) (*schema.UserInfo, *schema.Session, error)
	AuthenticateKey(ctx context.Context, token string) (*schema.UserInfo, *schema.Key, error)
}

Authenticator validates bearer tokens and API keys and returns the authenticated principal material used by downstream handlers.

type KeyAuthenticator added in v0.0.11

type KeyAuthenticator interface {
	AuthenticateKey(ctx context.Context, token string) (*schema.UserInfo, *schema.Key, error)
}

KeyAuthenticator validates an API key token and returns the authenticated principal material used by downstream handlers.

type Policy

type Policy interface {
	MatchUser(*schema.UserInfo) error
}

A policy object is used to implement authorization checks on the user

func MatchScopes

func MatchScopes(required ...string) Policy

Jump to

Keyboard shortcuts

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