diff options
Diffstat (limited to 'app/session.go')
-rw-r--r-- | app/session.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/session.go b/app/session.go new file mode 100644 index 0000000..58aa13d --- /dev/null +++ b/app/session.go | |||
@@ -0,0 +1,46 @@ | |||
1 | package app | ||
2 | |||
3 | import ( | ||
4 | "time" | ||
5 | |||
6 | "code.crute.us/mcrute/golib/echo/middleware" | ||
7 | "code.crute.us/mcrute/golib/echo/session" | ||
8 | "github.com/go-webauthn/webauthn/webauthn" | ||
9 | "github.com/labstack/echo/v4" | ||
10 | ) | ||
11 | |||
12 | type AppSession interface { | ||
13 | session.Session | ||
14 | middleware.CSRFAwareSession | ||
15 | Self() *Session | ||
16 | } | ||
17 | |||
18 | type Session struct { | ||
19 | Expiration time.Time | ||
20 | CSRFToken string | ||
21 | WebauthnSession *webauthn.SessionData | ||
22 | } | ||
23 | |||
24 | var _ AppSession = (*Session)(nil) | ||
25 | |||
26 | func NewSession(c echo.Context) *Session { | ||
27 | return &Session{ | ||
28 | Expiration: time.Now().Add(365 * 24 * time.Hour), | ||
29 | } | ||
30 | } | ||
31 | |||
32 | func (s *Session) Self() *Session { | ||
33 | return s | ||
34 | } | ||
35 | |||
36 | func (s *Session) Expires() time.Time { | ||
37 | return s.Expiration | ||
38 | } | ||
39 | |||
40 | func (s *Session) GetCSRFSecret() string { | ||
41 | return s.CSRFToken | ||
42 | } | ||
43 | |||
44 | func (s *Session) SetCSRFSecret(secret string) { | ||
45 | s.CSRFToken = secret | ||
46 | } | ||