summaryrefslogtreecommitdiff
path: root/app/session.go
blob: 58aa13d2f672a49262bc2602892a89d20a8d63dc (plain)
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
package app

import (
	"time"

	"code.crute.us/mcrute/golib/echo/middleware"
	"code.crute.us/mcrute/golib/echo/session"
	"github.com/go-webauthn/webauthn/webauthn"
	"github.com/labstack/echo/v4"
)

type AppSession interface {
	session.Session
	middleware.CSRFAwareSession
	Self() *Session
}

type Session struct {
	Expiration      time.Time
	CSRFToken       string
	WebauthnSession *webauthn.SessionData
}

var _ AppSession = (*Session)(nil)

func NewSession(c echo.Context) *Session {
	return &Session{
		Expiration: time.Now().Add(365 * 24 * time.Hour),
	}
}

func (s *Session) Self() *Session {
	return s
}

func (s *Session) Expires() time.Time {
	return s.Expiration
}

func (s *Session) GetCSRFSecret() string {
	return s.CSRFToken
}

func (s *Session) SetCSRFSecret(secret string) {
	s.CSRFToken = secret
}