authn

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CtxAuthenticated is the authenticated field in request context. It is
	// of type bool and set to true, if the request has been successfully,
	// authenticated and false otherwise.
	CtxAuthenticated ctxKey = "authenticated"

	// CtxUsername is the username field in request context.
	CtxUsername ctxKey = "username"

	// CtxProtocol is the protocol field in request context.
	CtxProtocol ctxKey = "protocol"
)

Context keys.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

func New

func New(authers []Auther) Authenticator

func (*Authenticator) Middleware

func (a *Authenticator) Middleware(opts ...MiddlewareOption) func(next http.HandlerFunc) http.HandlerFunc

Middleware returns a http handler middleware, which will try to authenticate a request by probing all provided authers in sequence. When successful, the authenticated username and the protocol of the authentication is stored in the request context.

type Auther

type Auther interface {
	Auth(w http.ResponseWriter, r *http.Request) (trusted bool, username string, protocol string, _ error)
}

type MiddlewareOption

type MiddlewareOption func(c *middlewareConfig)

func WithIsAuthenticationRequired

func WithIsAuthenticationRequired(isAuthenticationRequired func(r *http.Request) bool) MiddlewareOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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