Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultOnErrorResponse(_ ErrorResponseReason, _ error)
- func NewConstructor(options ...COption) func(http.Handler) http.Handler
- func NewEnforcer(options ...EOption) func(http.Handler) http.Handler
- func NewErrorHeaderer(err error, headers map[string][]string) error
- func NewListenerDecorator(listeners ...Listener) func(http.Handler) http.Handler
- func WriteResponse(response http.ResponseWriter, defaultStatusCode int, v interface{})
- type BasicTokenFactory
- type BearerTokenFactory
- type COption
- type EOption
- type ErrorHeaderer
- type ErrorResponseReason
- type Listener
- type NotFoundBehavior
- type OnErrorResponse
- type TokenFactory
- type TokenFactoryFunc
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 ¶
New returns an Alice-style constructor which decorates HTTP handlers with security code
func NewErrorHeaderer ¶ added in v0.1.1
func NewListenerDecorator ¶
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 ¶
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 ¶
type BearerTokenFactory ¶
type BearerTokenFactory struct { DefaultKeyId string Resolver key.Resolver Parser bascule.JWSParser JWTValidators []*jwt.Validator }
func (BearerTokenFactory) ParseAndValidate ¶
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 WithHeaderName ¶
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 WithNotFoundBehavior ¶ added in v0.2.0
func WithNotFoundBehavior(behavior NotFoundBehavior) EOption
func WithRules ¶
func WithRules(key bascule.Authorization, v bascule.Validators) 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 ¶
Click to show internal directories.
Click to hide internal directories.