auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(authenticator Authenticator) func(http.Handler) http.Handler

Middleware creates an authentication middleware

Types

type AuthType

type AuthType string

AuthType represents the type of authentication

const (
	AuthTypeNone   AuthType = "none"
	AuthTypeBasic  AuthType = "basic"
	AuthTypeBearer AuthType = "bearer"
)

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) error
}

Authenticator defines the interface for authentication

type BasicAuthenticator

type BasicAuthenticator struct {
	Username string
	Password string
}

BasicAuthenticator implements HTTP Basic authentication

func NewBasicAuthenticator

func NewBasicAuthenticator(username, password string) *BasicAuthenticator

NewBasicAuthenticator creates a new basic authenticator

func (*BasicAuthenticator) Authenticate

func (ba *BasicAuthenticator) Authenticate(r *http.Request) error

Authenticate validates basic authentication credentials

type BearerAuthenticator

type BearerAuthenticator struct {
	Token string
}

BearerAuthenticator implements Bearer token authentication

func NewBearerAuthenticator

func NewBearerAuthenticator(token string) *BearerAuthenticator

NewBearerAuthenticator creates a new bearer token authenticator

func (*BearerAuthenticator) Authenticate

func (ba *BearerAuthenticator) Authenticate(r *http.Request) error

Authenticate validates bearer token

type MultiAuthenticator

type MultiAuthenticator struct {
	Authenticators []Authenticator
}

MultiAuthenticator supports multiple authentication methods

func NewMultiAuthenticator

func NewMultiAuthenticator(authenticators ...Authenticator) *MultiAuthenticator

NewMultiAuthenticator creates a new multi-authenticator

func (*MultiAuthenticator) Authenticate

func (ma *MultiAuthenticator) Authenticate(r *http.Request) error

Authenticate tries each authenticator until one succeeds

type NoAuth

type NoAuth struct{}

NoAuth returns a no-op authenticator

func (*NoAuth) Authenticate

func (n *NoAuth) Authenticate(r *http.Request) error

Authenticate always succeeds

Jump to

Keyboard shortcuts

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