added discord token check to auth
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user