basculehttp

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHeaderName = "Authorization"
)

Variables

View Source
var (
	ErrorMalformedValue      = errors.New("expected <user>:<password> in decoded value")
	ErrorNotInMap            = errors.New("principal not found")
	ErrorInvalidPassword     = errors.New("invalid password")
	ErrorNoProtectedHeader   = errors.New("missing protected header")
	ErrorNoSigningMethod     = errors.New("signing method (alg) is missing or unrecognized")
	ErrorUnexpectedPayload   = errors.New("payload isn't a map of strings to interfaces")
	ErrorUnexpectedPrincipal = errors.New("principal isn't a string")
)

Functions

func DefaultOnErrorResponse added in v0.2.5

func DefaultOnErrorResponse(_ ErrorResponseReason, _ error)

default function does nothing

func NewConstructor

func NewConstructor(options ...COption) func(http.Handler) http.Handler

New returns an Alice-style constructor which decorates HTTP handlers with security code

func NewEnforcer

func NewEnforcer(options ...EOption) func(http.Handler) http.Handler

func NewErrorHeaderer added in v0.1.1

func NewErrorHeaderer(err error, headers map[string][]string) error

func NewListenerDecorator

func NewListenerDecorator(listeners ...Listener) func(http.Handler) http.Handler

func WriteResponse

func WriteResponse(response http.ResponseWriter, defaultStatusCode int, v interface{})

WriteResponse performs some basic reflection on v to allow it to modify responses written to an HTTP response. Useful mainly for errors.

Types

type BasicTokenFactory

type BasicTokenFactory map[string]string

An example TokenFactory that this package should supply in some form. This type allows client code to simply use an in-memory map of users and passwords to authenticate against. Other implementations might look things up in a database, etc.

func (BasicTokenFactory) ParseAndValidate

func (btf BasicTokenFactory) ParseAndValidate(ctx context.Context, _ *http.Request, _ bascule.Authorization, value string) (bascule.Token, error)

type BearerTokenFactory

type BearerTokenFactory struct {
	DefaultKeyId  string
	Resolver      key.Resolver
	Parser        bascule.JWSParser
	JWTValidators []*jwt.Validator
}

func (BearerTokenFactory) ParseAndValidate

func (btf BearerTokenFactory) ParseAndValidate(ctx context.Context, _ *http.Request, _ bascule.Authorization, value string) (bascule.Token, error)

type COption

type COption func(*constructor)

func WithCErrorResponseFunc added in v0.2.5

func WithCErrorResponseFunc(f OnErrorResponse) COption

func WithCLogger added in v0.2.0

func WithCLogger(getLogger func(context.Context) bascule.Logger) COption

func WithHeaderName

func WithHeaderName(headerName string) COption

func WithTokenFactory

func WithTokenFactory(key bascule.Authorization, tf TokenFactory) COption

type EOption

type EOption func(*enforcer)

func WithEErrorResponseFunc added in v0.2.5

func WithEErrorResponseFunc(f OnErrorResponse) EOption

func WithELogger added in v0.2.0

func WithELogger(getLogger func(context.Context) bascule.Logger) EOption

func WithNotFoundBehavior added in v0.2.0

func WithNotFoundBehavior(behavior NotFoundBehavior) EOption

type ErrorHeaderer added in v0.1.1

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

func (ErrorHeaderer) Error added in v0.1.1

func (e ErrorHeaderer) Error() string

func (ErrorHeaderer) Headers added in v0.1.1

func (e ErrorHeaderer) Headers() http.Header

type ErrorResponseReason added in v0.2.5

type ErrorResponseReason int
const (
	MissingHeader ErrorResponseReason = iota
	InvalidHeader
	KeyNotSupported
	ParseFailed
	MissingAuthentication
	ChecksNotFound
	ChecksFailed
)

Behavior on not found

func (ErrorResponseReason) String added in v0.2.5

func (i ErrorResponseReason) String() string

type Listener

type Listener interface {
	OnAuthenticated(bascule.Authentication)
}

type NotFoundBehavior added in v0.2.0

type NotFoundBehavior int
const (
	Forbid NotFoundBehavior = iota
	Allow
)

Behavior on not found

func (NotFoundBehavior) String added in v0.2.0

func (i NotFoundBehavior) String() string

type OnErrorResponse added in v0.2.5

type OnErrorResponse func(ErrorResponseReason, error)

type TokenFactory

type TokenFactory interface {
	ParseAndValidate(context.Context, *http.Request, bascule.Authorization, string) (bascule.Token, error)
}

TokenFactory is a strategy interface responsible for creating and validating a secure token

type TokenFactoryFunc

type TokenFactoryFunc func(context.Context, *http.Request, bascule.Authorization, string) (bascule.Token, error)

func (TokenFactoryFunc) ParseAndValidate

func (tff TokenFactoryFunc) ParseAndValidate(ctx context.Context, r *http.Request, a bascule.Authorization, v string) (bascule.Token, error)

Jump to

Keyboard shortcuts

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