-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauth.go
More file actions
77 lines (61 loc) · 1.61 KB
/
auth.go
File metadata and controls
77 lines (61 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"context"
abclientstate "github.com/volatiletech/authboss-clientstate"
"github.com/volatiletech/authboss/v3"
"github.com/volatiletech/authboss/v3/defaults"
)
var (
ab = authboss.New()
database = NewMemStorer()
sessionStore abclientstate.SessionStorer
cookieStore abclientstate.CookieStorer
)
func SetupAuthboss() *authboss.Authboss {
ab.Config.Paths.RootURL = "http://localhost:3000"
ab.Config.Modules.LogoutMethod = "GET"
ab.Config.Storage.Server = database
ab.Config.Storage.SessionState = sessionStore
ab.Config.Storage.CookieState = cookieStore
ab.Config.Core.ViewRenderer = defaults.JSONRenderer{}
defaults.SetCore(&ab.Config, true, false)
if err := ab.Init(); err != nil {
panic(err)
}
return ab
}
type User struct {
ID int
Email string
Password string
}
func (u User) GetPID() string { return u.Email }
func (u *User) PutPID(pid string) { u.Email = pid }
type MemStorer struct {
Users map[string]User
Tokens map[string][]string
}
func NewMemStorer() *MemStorer {
return &MemStorer{
Users: map[string]User{
"rick@councilofricks.com": {
ID: 1,
Password: "$2a$10$XtW/BrS5HeYIuOCXYe8DFuInetDMdaarMUJEOg/VA/JAIDgw3l4aG", // pass = 1234
Email: "rick@councilofricks.com",
},
},
Tokens: make(map[string][]string),
}
}
func (m MemStorer) Save(_ context.Context, user authboss.User) error {
u := user.(*User)
m.Users[u.Email] = *u
return nil
}
func (m MemStorer) Load(_ context.Context, key string) (user authboss.User, err error) {
u, ok := m.Users[key]
if !ok {
return nil, authboss.ErrUserNotFound
}
return &u, nil
}