Skip to content

janekolszak/rememberme

Repository files navigation

RememberMe Build Status Code Climate GoDoc Join the chat at https://gitter.im/go-rememberme/Lobby

Go implementation of persistent login cookies. The implementation idea is described here

The library uses gorilla sessions for saving cookies on user site. Part of the persistant login information is stored on a server side in a dedicated Store. There are two store implementations available out of the box:

  • SQL database store
  • RethinkDB store

Installation

go get -u github.com/janekolszak/rememberme

Usage

Initialization

// Create the store
dbCookieStore, err := sqlstore.New("sqlite3", "/tmp/database.db3")
if err != nil {
	panic(err)
}

// Create Rememberme
auth = &rememberme.New{
	Store:  dbCookieStore,
	MaxAge: time.Second * 30,
}

Sign-in handler

func(w http.ResponseWriter, r *http.Request) {

	selector, userid, err := auth.Check(r)
	if err == nil {
		// Authenticated with a RememberMe Cookie
		err = auth.UpdateCookie(w, r, selector, userid)
		if err != nil {
			panic(err)
		}
	} else {
			// Can't authenticate with "Remember Me" cookie,
			// so try with another provider.

			// userid = Authenticated User ID

			// Save the RememberMe cookie
			err = auth.SetCookie(w, r, userid)
			if err != nil {
				panic(err)
			}
	}

	// User authenticated, cookie saved
	// ...
}

About

Go implementation of persistent login cookies

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages