goth: github.com/jroes/goth Index | Files | Directories

package goth

import "github.com/jroes/goth"

Package goth provides an authentication system for Go web apps.

Index

Package Files

goth.go handlers.go

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/"),
}

type AuthHandler Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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.

Directories

PathSynopsis
examples
user
user/gobstore

Package goth imports 7 packages (graph) and is imported by 1 packages. Updated 2016-07-15. Refresh now. Tools for package owners.