Skip to content

Commit

Permalink
Split out the session and cookie stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondl committed May 14, 2018
1 parent 07ae457 commit 96684a7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 214 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ This is a simple blogging engine with a few basic features:
- Support for API style JSON requests and responses (-api flag)
- Various levels of debugging to see what's going wrong (-debug* flags)

Uses the following default libraries:

- https://github.com/volatiletech/authboss-renderer
- https://github.com/volatiletech/authboss-clientstate

# Disclaimer

This sample is **NOT** a seed project. Do not use it as one.
Expand Down
21 changes: 14 additions & 7 deletions blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/BurntSushi/toml"
"github.com/volatiletech/authboss"
"github.com/volatiletech/authboss-renderer"
_ "github.com/volatiletech/authboss/auth"
"github.com/volatiletech/authboss/confirm"
"github.com/volatiletech/authboss/defaults"
Expand All @@ -28,14 +27,15 @@ import (
_ "github.com/volatiletech/authboss/register"
"github.com/volatiletech/authboss/remember"

"github.com/volatiletech/authboss-clientstate"
"github.com/volatiletech/authboss-renderer"

"golang.org/x/oauth2"
"golang.org/x/oauth2/google"

"github.com/aarondl/tpl"
"github.com/go-chi/chi"
"github.com/gorilla/schema"
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
"github.com/justinas/nosurf"
)

Expand All @@ -58,9 +58,16 @@ var (
database = NewMemStorer()
schemaDec = schema.NewDecoder()

sessionStore abclientstate.SessionStorer
cookieStore abclientstate.CookieStorer

templates tpl.Templates
)

const (
sessionCookieName = "ab_blog"
)

func setupAuthboss() {
ab.Config.Paths.RootURL = "http://localhost:3000"

Expand All @@ -75,8 +82,8 @@ func setupAuthboss() {
// These are all from this package since the burden is on the
// implementer for these.
ab.Config.Storage.Server = database
ab.Config.Storage.SessionState = NewSessionStorer()
ab.Config.Storage.CookieState = NewCookieStorer()
ab.Config.Storage.SessionState = sessionStore
ab.Config.Storage.CookieState = cookieStore

// Another piece that we're responsible for: Rendering views.
// Though note that we're using the authboss-renderer package
Expand Down Expand Up @@ -198,8 +205,8 @@ func main() {
// a configuration environment var or file.
cookieStoreKey, _ := base64.StdEncoding.DecodeString(`NpEPi8pEjKVjLGJ6kYCS+VTCzi6BUuDzU0wrwXyf5uDPArtlofn2AG6aTMiPmN3C909rsEWMNqJqhIVPGP3Exg==`)
sessionStoreKey, _ := base64.StdEncoding.DecodeString(`AbfYwmmt8UCwUuhd9qvfNA9UCuN1cVcKJN1ofbiky6xCyyBj20whe40rJa3Su0WOWLWcPpO1taqJdsEI/65+JA==`)
cookieStore = securecookie.New(cookieStoreKey, nil)
sessionStore = sessions.NewCookieStore(sessionStoreKey)
cookieStore = abclientstate.NewCookieStorer(cookieStoreKey, nil)
sessionStore = abclientstate.NewSessionStorer(sessionCookieName, sessionStoreKey, nil)

// Initialize authboss
setupAuthboss()
Expand Down
86 changes: 0 additions & 86 deletions cookie_storer.go

This file was deleted.

121 changes: 0 additions & 121 deletions session_storer.go

This file was deleted.

0 comments on commit 96684a7

Please sign in to comment.