Track recently used totp timestamps
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Melody Becker 2025-04-01 09:16:33 +02:00
parent a6bcbaf5e9
commit 7ae75caaf5
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
3 changed files with 29 additions and 1 deletions

View file

@ -9,6 +9,7 @@ package auth
import (
"time"
"git.mstar.dev/mstar/goutils/other"
"git.mstar.dev/mstar/goutils/sliceutils"
"github.com/go-webauthn/webauthn/webauthn"
@ -18,7 +19,8 @@ import (
)
type Authenticator struct {
webauthn *webauthn.WebAuthn
webauthn *webauthn.WebAuthn
recentlyUsedTotpTokens map[string]time.Time
}
type LoginNextState uint8
@ -33,6 +35,17 @@ const (
LoginStartPasskey // Login starts with a passkey
)
func New(webauthnConfig *webauthn.Config) (*Authenticator, error) {
webauthn, err := webauthn.New(webauthnConfig)
if err != nil {
return nil, other.Error("auth", "failed to create webauthn handler", err)
}
return &Authenticator{
webauthn: webauthn,
recentlyUsedTotpTokens: make(map[string]time.Time),
}, nil
}
func calcAccessExpirationTimestamp() time.Time {
// For now, the default expiration is one month after creation
// though "never" might also be a good option