Documentation ¶
Overview ¶
Package goth provides an authentication system for Go web apps.
Index ¶
- Variables
- type AuthHandler
- func (handler AuthHandler) CurrentUser(r *http.Request) (*User, bool)
- func (handler AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (handler AuthHandler) SignInHandler(w http.ResponseWriter, r *http.Request)
- func (handler AuthHandler) SignOutHandler(w http.ResponseWriter, r *http.Request)
- func (handler AuthHandler) SignUpHandler(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
var DefaultAuthHandler = AuthHandler{ RoutePath: "/auth/", TemplatePath: "tmpl/", AfterSignupPath: "/", AfterSigninPath: "/", AfterSignoutPath: "/", SessionSecret: "change-me-please", SessionStore: sessions.NewCookieStore([]byte("change-me-please")), UserStore: gobstore.NewUserGobStore("users/"), }
Functions ¶
This section is empty.
Types ¶
type AuthHandler ¶
type AuthHandler struct { // Where to mount URLs for authentication (e.g. signup, signin) RoutePath string // Where on disk HTML templates are stored for authentication pages. TemplatePath string // Where to redirect the user after various authentication operations. AfterSignupPath string AfterSigninPath string AfterSignoutPath string // This should be set to a string of characters used to encrypt and sign // sessions. It should be kept private from any source repositories. You could // use os.Getenv() for this and store it in an environment variable. SessionSecret string SessionStore *sessions.CookieStore UserStore UserStore }
func (AuthHandler) CurrentUser ¶
func (handler AuthHandler) CurrentUser(r *http.Request) (*User, bool)
CurrentUser retrieves the User object for the currently logged in user based on the request. The first return value is the User object, the second is true if a user is logged in. If a user is not logged in, the first return value will be an empty User, and the second return value will be false.
func (AuthHandler) ServeHTTP ¶
func (handler AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface to delegate authentication-related routing to the proper handler.
func (AuthHandler) SignInHandler ¶
func (handler AuthHandler) SignInHandler(w http.ResponseWriter, r *http.Request)
SignInHandler validates email and password parameters in an HTTP request against the UserStore. If the provided parameters are valid, a session will be created for the user and an HTTP redirect will be returned to the AfterSigninPath.
func (AuthHandler) SignOutHandler ¶
func (handler AuthHandler) SignOutHandler(w http.ResponseWriter, r *http.Request)
SignOutHandler instructs the browser to clear the session and redirects the client to the AfterSignoutPath.
func (AuthHandler) SignUpHandler ¶
func (handler AuthHandler) SignUpHandler(w http.ResponseWriter, r *http.Request)
SignUpHandler handles both GET and POST requests. With a GET request, it renders a sign up template form that will POST to the same route. With a POST request, it creates a user via the UserStore with the specified email and password parameters. After successfully creating a User, it will redirect to the AfterSignupPath.