Skip to content

jroes/goth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Goth

Build Status

Goth is a web authentication system written in Go. With Goth, you get out-of- the-box user sign in, sign up, and sign out functionality to kick off building your web app.

Disclaimer

Not ready for production yet! Use at your own risk. File bugs, pitch in, etc.

Installation

go get github.com/jroes/goth

Usage

The following example mounts goth's authentication handler at /auth/, and registers a simple handler for the root route that greets the user with the user's e-mail address if logged in, or as a guest if not.

package main

import (
	"fmt"
	"net/http"
)

import (
	"github.com/jroes/goth"
)

var authHandler = goth.DefaultAuthHandler

func main() {
	http.Handle("/auth/", authHandler)
	http.HandleFunc("/", helloUserHandler)

	// Please use ListenAndServeTLS in production.
	http.ListenAndServe(":8080", nil)
}

func helloUserHandler(w http.ResponseWriter, r *http.Request) {
	currentUser, ok := authHandler.CurrentUser(r)
	if ok {
		fmt.Fprintf(w, "Hello, %s!", currentUser.Email)
	} else {
		fmt.Fprintf(w, "Hello, guest!")
	}
}

So what does this get you exactly? You get a bunch of routes underneath /auth/:

HTTP Method URL Description
GET http://localhost:8080/auth/sign_up Standard sign up form
POST http://localhost:8080/auth/sign_up Creates User and persists using the defined UserStore (default: UserGobStore, a store persisted in Go's gob format on disk)
GET http://localhost:8080/auth/sign_in Standard sign in form
POST http://localhost:8080/auth/sign_in Creates a session (default: cookie-based through gorilla/sessions)
POST http://localhost:8080/auth/sign_out Expires the session (default: expires the cookie from gorilla/sessions)

About

Authentication for Go web apps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages