Documentation ¶
Overview ¶
Package auth contains user authentication code for webservers.
Basic access authentication requires a client to provide a user name and password with each request. Most browsers will directly support this method. See: https://en.wikipedia.org/wiki/Basic_access_authentication
Cookie based authentication requires the client to login once and create a unique access token. The access token is then used to authenticate each request.
Index ¶
- Variables
- type BashicAuthHandleFuncWrapper
- func (bw *BashicAuthHandleFuncWrapper) CheckAuth(r *http.Request) (string, bool)
- func (bw *BashicAuthHandleFuncWrapper) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (bw *BashicAuthHandleFuncWrapper) SetAccessFunc(accessFunc func(http.ResponseWriter, *http.Request, string) bool)
- func (bw *BashicAuthHandleFuncWrapper) SetAuthFunc(authFunc func(user, pass string) bool)
- type CookieAuthHandleFuncWrapper
- func (cw *CookieAuthHandleFuncWrapper) AddPublicPage(url string, handler func(http.ResponseWriter, *http.Request))
- func (cw *CookieAuthHandleFuncWrapper) AuthUser(user, pass string, testOnly bool) string
- func (cw *CookieAuthHandleFuncWrapper) CheckAuth(r *http.Request) (string, bool)
- func (cw *CookieAuthHandleFuncWrapper) Expiry() int
- func (cw *CookieAuthHandleFuncWrapper) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (cw *CookieAuthHandleFuncWrapper) InvalidateAuthCookie(r *http.Request)
- func (cw *CookieAuthHandleFuncWrapper) RemoveAuthCookie(w http.ResponseWriter)
- func (cw *CookieAuthHandleFuncWrapper) SetAccessFunc(accessFunc func(http.ResponseWriter, *http.Request, string) bool)
- func (cw *CookieAuthHandleFuncWrapper) SetAuthCookie(yaid string, w http.ResponseWriter)
- func (cw *CookieAuthHandleFuncWrapper) SetAuthFunc(authFunc func(user, pass string) bool)
- func (cw *CookieAuthHandleFuncWrapper) SetExpiry(secs int)
- type HandleFuncWrapper
Constants ¶
This section is empty.
Variables ¶
var CookieMaxLifetime = 3600
CookieMaxLifetime is the max life time of an auth cookie in seconds
var Realm = "RestrictedAccessRealm"
Realm is the authentication realm
var TestCookieAuthDisabled = false
TestCookieAuthDisabled is a flag to disable cookie based authentication temporarily (should only be used by unit tests)
Functions ¶
This section is empty.
Types ¶
type BashicAuthHandleFuncWrapper ¶
type BashicAuthHandleFuncWrapper struct { CallbackSessionExpired func(w http.ResponseWriter, r *http.Request) // contains filtered or unexported fields }
BashicAuthHandleFuncWrapper datastructure. Wrapper for HandleFunc to add basic authentication to all added endpoints.
func NewBashicAuthHandleFuncWrapper ¶
func NewBashicAuthHandleFuncWrapper(origHandleFunc func(pattern string, handler func(http.ResponseWriter, *http.Request))) *BashicAuthHandleFuncWrapper
NewBashicAuthHandleFuncWrapper creates a new HandleFunc wrapper.
func (*BashicAuthHandleFuncWrapper) CheckAuth ¶
func (bw *BashicAuthHandleFuncWrapper) CheckAuth(r *http.Request) (string, bool)
CheckAuth checks the user authentication of an incomming request. Returns if the authentication is correct and the given username.
func (*BashicAuthHandleFuncWrapper) HandleFunc ¶
func (bw *BashicAuthHandleFuncWrapper) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
HandleFunc is the new handle func which wraps an original handle functions to do an authentication check.
func (*BashicAuthHandleFuncWrapper) SetAccessFunc ¶
func (bw *BashicAuthHandleFuncWrapper) SetAccessFunc(accessFunc func(http.ResponseWriter, *http.Request, string) bool)
SetAccessFunc sets an access function which can be used by the wrapper to check the user access rights.
func (*BashicAuthHandleFuncWrapper) SetAuthFunc ¶
func (bw *BashicAuthHandleFuncWrapper) SetAuthFunc(authFunc func(user, pass string) bool)
SetAuthFunc gives an authentication function which can be used by the wrapper to authenticate users.
type CookieAuthHandleFuncWrapper ¶
type CookieAuthHandleFuncWrapper struct { CallbackSessionExpired func(w http.ResponseWriter, r *http.Request) // contains filtered or unexported fields }
CookieAuthHandleFuncWrapper datastructure. Wrapper for HandleFunc to add cookie authentication to all added endpoints.
func NewCookieAuthHandleFuncWrapper ¶
func NewCookieAuthHandleFuncWrapper(origHandleFunc func(pattern string, handler func(http.ResponseWriter, *http.Request))) *CookieAuthHandleFuncWrapper
NewCookieAuthHandleFuncWrapper creates a new HandleFunc wrapper.
func (*CookieAuthHandleFuncWrapper) AddPublicPage ¶
func (cw *CookieAuthHandleFuncWrapper) AddPublicPage(url string, handler func(http.ResponseWriter, *http.Request))
AddPublicPage adds a page which should be accessible without authentication. using a special handler.
func (*CookieAuthHandleFuncWrapper) AuthUser ¶
func (cw *CookieAuthHandleFuncWrapper) AuthUser(user, pass string, testOnly bool) string
AuthUser authenticates a user and creates an auth token unless testOnly is true. Returns an empty string if the authentication was not successful.
func (*CookieAuthHandleFuncWrapper) CheckAuth ¶
func (cw *CookieAuthHandleFuncWrapper) CheckAuth(r *http.Request) (string, bool)
CheckAuth checks the user authentication of an incomming request. Returns if the authentication is correct and the given username.
func (*CookieAuthHandleFuncWrapper) Expiry ¶
func (cw *CookieAuthHandleFuncWrapper) Expiry() int
Expiry returns the current authentication expiry time in seconds.
func (*CookieAuthHandleFuncWrapper) HandleFunc ¶
func (cw *CookieAuthHandleFuncWrapper) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
HandleFunc is the new handle func which wraps an original handle functions to do an authentication check.
func (*CookieAuthHandleFuncWrapper) InvalidateAuthCookie ¶
func (cw *CookieAuthHandleFuncWrapper) InvalidateAuthCookie(r *http.Request)
InvalidateAuthCookie invalidates the authentication of an incomming request.
func (*CookieAuthHandleFuncWrapper) RemoveAuthCookie ¶
func (cw *CookieAuthHandleFuncWrapper) RemoveAuthCookie(w http.ResponseWriter)
RemoveAuthCookie removes the auth cookie in a given response object and invalidates it.
func (*CookieAuthHandleFuncWrapper) SetAccessFunc ¶
func (cw *CookieAuthHandleFuncWrapper) SetAccessFunc(accessFunc func(http.ResponseWriter, *http.Request, string) bool)
SetAccessFunc sets an access function which can be used by the wrapper to check the user access rights.
func (*CookieAuthHandleFuncWrapper) SetAuthCookie ¶
func (cw *CookieAuthHandleFuncWrapper) SetAuthCookie(yaid string, w http.ResponseWriter)
SetAuthCookie sets the auth cookie in a given response object.
func (*CookieAuthHandleFuncWrapper) SetAuthFunc ¶
func (cw *CookieAuthHandleFuncWrapper) SetAuthFunc(authFunc func(user, pass string) bool)
SetAuthFunc sets an authentication function which can be used by the wrapper to authenticate users.
func (*CookieAuthHandleFuncWrapper) SetExpiry ¶
func (cw *CookieAuthHandleFuncWrapper) SetExpiry(secs int)
SetExpiry sets the authentication expiry time in seconds. All existing authentications are retracted during this function call.
type HandleFuncWrapper ¶
type HandleFuncWrapper interface { /* SetAuthFunc gives an authentication function which can be used by the wrapper to authenticate users. */ SetAuthFunc(authFunc func(user, pass string) bool) /* HandleFunc is the new handle func which wraps an original handle functions to do an authentication check. */ HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) /* CheckAuth checks the user authentication of an incomming request. Returns if the authentication is correct and the given username. */ CheckAuth(r *http.Request) (string, bool) }
HandleFuncWrapper is an abstract wrapper for handle functions to add authentication features.