Skip to content

Commit 96684a7

Browse files
committed
Split out the session and cookie stuff
1 parent 07ae457 commit 96684a7

File tree

4 files changed

+19
-214
lines changed

4 files changed

+19
-214
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ This is a simple blogging engine with a few basic features:
1111
- Support for API style JSON requests and responses (-api flag)
1212
- Various levels of debugging to see what's going wrong (-debug* flags)
1313

14+
Uses the following default libraries:
15+
16+
- https://github.com/volatiletech/authboss-renderer
17+
- https://github.com/volatiletech/authboss-clientstate
18+
1419
# Disclaimer
1520

1621
This sample is **NOT** a seed project. Do not use it as one.

blog.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"github.com/BurntSushi/toml"
1919
"github.com/volatiletech/authboss"
20-
"github.com/volatiletech/authboss-renderer"
2120
_ "github.com/volatiletech/authboss/auth"
2221
"github.com/volatiletech/authboss/confirm"
2322
"github.com/volatiletech/authboss/defaults"
@@ -28,14 +27,15 @@ import (
2827
_ "github.com/volatiletech/authboss/register"
2928
"github.com/volatiletech/authboss/remember"
3029

30+
"github.com/volatiletech/authboss-clientstate"
31+
"github.com/volatiletech/authboss-renderer"
32+
3133
"golang.org/x/oauth2"
3234
"golang.org/x/oauth2/google"
3335

3436
"github.com/aarondl/tpl"
3537
"github.com/go-chi/chi"
3638
"github.com/gorilla/schema"
37-
"github.com/gorilla/securecookie"
38-
"github.com/gorilla/sessions"
3939
"github.com/justinas/nosurf"
4040
)
4141

@@ -58,9 +58,16 @@ var (
5858
database = NewMemStorer()
5959
schemaDec = schema.NewDecoder()
6060

61+
sessionStore abclientstate.SessionStorer
62+
cookieStore abclientstate.CookieStorer
63+
6164
templates tpl.Templates
6265
)
6366

67+
const (
68+
sessionCookieName = "ab_blog"
69+
)
70+
6471
func setupAuthboss() {
6572
ab.Config.Paths.RootURL = "http://localhost:3000"
6673

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

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

204211
// Initialize authboss
205212
setupAuthboss()

cookie_storer.go

-86
This file was deleted.

session_storer.go

-121
This file was deleted.

0 commit comments

Comments
 (0)