auth/store/memory.go
2023-10-21 10:26:15 +02:00

47 lines
848 B
Go

package store
type MemoryAuthStore struct {
Tokens map[string]RevokableToken
}
func NewMemoryAuthStore() *MemoryAuthStore {
return &MemoryAuthStore{Tokens: map[string]RevokableToken{}}
}
func (s *MemoryAuthStore) Revoke(id string) error {
if t, ok := s.Tokens[id]; ok {
t.Revoked = true
s.Tokens[id] = t
}
return nil
}
func (s *MemoryAuthStore) IsRevoked(id string) bool {
if t, ok := s.Tokens[id]; ok {
return t.Revoked
}
return false
}
func (s *MemoryAuthStore) Add(token RevokableToken) error {
s.Tokens[token.ID] = token
return nil
}
func (s *MemoryAuthStore) Remove(id string) error {
delete(s.Tokens, id)
return nil
}
func (s *MemoryAuthStore) RevokeUser(subject string) error {
for id, token := range s.Tokens {
if token.Subject == subject {
token.Revoked = true
s.Tokens[id] = token
}
}
return nil
}