Documentation
¶
Index ¶
- type Auth
- func (a *Auth) HandleLogin(w http.ResponseWriter, r *http.Request)
- func (a *Auth) HandleLogout(w http.ResponseWriter, r *http.Request)
- func (a *Auth) Handler(h http.Handler) http.Handler
- func (a *Auth) IsAuthenticated(r *http.Request) bool
- func (a *Auth) Login(w http.ResponseWriter, hashedPw string)
- func (a *Auth) LoginFormHTML(r *http.Request) string
- func (a *Auth) Logout(w http.ResponseWriter)
- func (a *Auth) Solo(next http.HandlerFunc) http.HandlerFunc
- func (a *Auth) SoloH(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth is a middleware that provides password authentication. It also contains custom handlers (login, logout) for basic auth flow.
func (*Auth) HandleLogin ¶
func (a *Auth) HandleLogin(w http.ResponseWriter, r *http.Request)
HandleLogin handles the logic for logging in a user. On GET, login form is shown. On POST, cookie is generated if passwords match.
func (*Auth) HandleLogout ¶
func (a *Auth) HandleLogout(w http.ResponseWriter, r *http.Request)
HandleLogout handles the logic for logging out a user. The cookie is cleared and it redirects to the configured loginURL.
func (*Auth) Handler ¶
Handler wraps an http.Handler and injects the internal handlers for logging in and logging out.
func (*Auth) IsAuthenticated ¶
IsAuthenticated checks if a user is logged in. It checks an http.Request to see if the cookie's hash matches the one stored in the middleware.
func (*Auth) Login ¶
func (a *Auth) Login(w http.ResponseWriter, hashedPw string)
Login creates a cookie with the hashed password, and sets it on the ResponseWriter.
func (*Auth) LoginFormHTML ¶
LoginFormHTML creates and returns a login form with the resolved loginSuccessURL.
func (*Auth) Logout ¶
func (a *Auth) Logout(w http.ResponseWriter)
Logout removes the cookie from the ResponseWriter.
func (*Auth) Solo ¶
func (a *Auth) Solo(next http.HandlerFunc) http.HandlerFunc
Solo provides the auth functionality for an http.HandlerFunc.