Documentation ¶
Index ¶
- Variables
- type Auther
- type ErrorHandler
- type Handler
- func (ah Handler) Authenticate(next http.Handler) http.Handler
- func (ah Handler) AuthenticateRequest(r *http.Request) (interface{}, error)
- func (ah Handler) Authorize(w http.ResponseWriter, r *http.Request)
- func (ah Handler) Logout(w http.ResponseWriter, r *http.Request)
- func (ah Handler) SaveUserSession(r *http.Request, w http.ResponseWriter, userData interface{}) error
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadLogin = errors.New("Bad Login") ErrNotAuthorized = errors.New("Not Authorized") )
errors to be checked against returned
Functions ¶
This section is empty.
Types ¶
type Auther ¶
type Auther interface { // Check should return a non-nil error for failed requests (like ErrBadLogin) // and it can pass custom data that is saved in the cookie through the first return argument Check(user, pass string) (interface{}, error) }
Auther allows for custom authentication backends
type ErrorHandler ¶ added in v1.7.0
ErrorHandler is used to for the SetErrorHandler option. It is a classical http.HandleFunc plus the error and response code the auth system determained.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler exposes helper functions to login/authorize, logout and authenticate http requests.
func NewHandler ¶
NewHandler returns a configured Handler value, using the passed Auther and options.
func (Handler) Authenticate ¶
Authenticate calls the next unless AuthenticateRequest returns an error
func (Handler) AuthenticateRequest ¶
AuthenticateRequest uses the passed request to load and return the session data that was stored previously. If it is invalid or there is no session, it will return ErrNotAuthorized.
func (Handler) Authorize ¶
func (ah Handler) Authorize(w http.ResponseWriter, r *http.Request)
Authorize is a http.HandlerFunc to authorize a login POST request (with form fields user and pass) and passes them to the configured Auther to check them before the return value is saved in the configured session store.
func (Handler) Logout ¶
func (ah Handler) Logout(w http.ResponseWriter, r *http.Request)
Logout destroys the session data and updates the cookie with an invalidated one.
func (Handler) SaveUserSession ¶ added in v1.9.0
func (ah Handler) SaveUserSession(r *http.Request, w http.ResponseWriter, userData interface{}) error
SaveUserSession a way to manually Authorize a session and create a cookie for a user.
type Option ¶
Option is a function that changes a handler in a certain way during initialization
func SetErrorHandler ¶ added in v1.7.0
func SetErrorHandler(errh ErrorHandler) Option
SetErrorHandler can be used to customize the look up error responses
func SetLanding ¶
SetLanding sets the url to where a client is redirect to after login
func SetLifetime ¶
SetLifetime sets the duration of when a session expires after it is created
func SetLogout ¶
SetLogout sets the url to where a client is redirect to after logout uses Landing location by default
func SetNotAuthorizedHandler ¶ added in v1.7.0
SetNotAuthorizedHandler re-routes the _not authorized_ response to a different http handler
func SetSessionName ¶
SetSessionName sets the name to use for sessions (ie. cookie name)