Documentation ¶
Index ¶
Constants ¶
const ( AUTHMODEREQUIRED = "required" AUTMODETRY = "try" AUTHMODENONE = "none" )
AuthMode constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bundler ¶
type Bundler struct { EW ErrorWriter // contains filtered or unexported fields }
Bundler bundles authentication, authorization, validation and per HandlerFunc logic into a nice package.
func (*Bundler) New ¶
New returns a bundled HandlerFunc. New may panic if options are incorrect that could result in a invalid or insecure configuration.
func (*Bundler) RegisterScheme ¶
RegisterScheme registers the scheme by name with bundler. It can then be used in O.Schemes.
func (*Bundler) SetDefaultScheme ¶
SetDefaultScheme sets the scheme name that will be used for every bundled HandlerFunc. Error will be returned if the scheme has not been registered.
type CtxCredentials ¶
type CtxCredentials struct{}
CtxCredentials is the key for the request context value holding credentials returned from Scheme.Authenticate.
type DefaultErrorWriter ¶
type DefaultErrorWriter struct {
// contains filtered or unexported fields
}
DefaultErrorWriter is the default ErrorWriter used by Bundler.
func (DefaultErrorWriter) WriteError ¶
func (d DefaultErrorWriter) WriteError(w http.ResponseWriter, _ *http.Request, err error)
WriteError writes an error to the ResponseWriter as JSON.
type ErrorWriter ¶
type ErrorWriter interface {
WriteError(w http.ResponseWriter, r *http.Request, err error)
}
ErrorWriter implements error handling for bundles HandlerFunc. err is a boom.Error and has information such as status codes. Seee DefaultErrorWriter for implementation details.
type HandleWrap ¶
type HandleWrap func(func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)
HandleWrap is a function that takes a HandlerFunc and returns a HandlerFunc.
func WrapSlice ¶
func WrapSlice(funcs ...HandleWrap) []HandleWrap
WrapSlice takes a variable amount of HandleWraps and returns a slice. This is a convienience function for setting O.Before.
type O ¶
type O struct { Allow []string // Content-Types to allow. Roles []string // Roles to allow, object in request context with key CtxCredentials must implement Roler. Schemes []string // A series of authentication schemes to try in order. Must be registered with Bundler. AuthMode string // 'try', 'required', 'none'. Before []HandleWrap // A series of HandlerFuncs to execute before Handle. After []HandleWrap // A serios of HandlerFuncs to execute after Handle. HandlerFunc func(http.ResponseWriter, *http.Request) }
O are options to pass to Bundle.
type Roler ¶
Roler is in interface used during authorization to validate that the implementer has the required role.
type Scheme ¶
type Scheme interface {
Authenticate(w http.ResponseWriter, r *http.Request) (interface{}, error)
}
Scheme is an abstraction layer around a session management and authentication scheme. Authenticate should authenticate a request and return credentials or an error. Any presence of an error will indicate an authentication failure.