added discord token check to auth

This commit is contained in:
2026-02-07 18:02:12 +11:00
parent 697bef80e9
commit 7125683e6a
9 changed files with 183 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
// Package store provides a session store for caching data
package store
import (
@@ -22,6 +23,7 @@ type Store struct {
sessions sync.Map // key: string, value: *RegistrationSession
redirectTracks sync.Map // key: string, value: *RedirectTrack
cleanup *time.Ticker
tokenchecks sync.Map // key: int, value: *TokenCheck
}
func NewStore() *Store {
@@ -42,6 +44,7 @@ func NewStore() *Store {
func (s *Store) Delete(id string) {
s.sessions.Delete(id)
}
func (s *Store) cleanupExpired() {
now := time.Now()
@@ -62,10 +65,19 @@ func (s *Store) cleanupExpired() {
}
return true
})
s.tokenchecks.Range(func(key, value any) bool {
check := value.(*TokenCheck)
if now.After(check.ExpiresAt) {
s.tokenchecks.Delete(key)
}
return true
})
}
func generateID() string {
b := make([]byte, 32)
rand.Read(b)
_, _ = rand.Read(b)
return base64.RawURLEncoding.EncodeToString(b)
}