forked from sqrldev/server-go-ssp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_auth_store.go
43 lines (37 loc) · 1.04 KB
/
map_auth_store.go
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
package ssp
import (
"fmt"
"log"
"sync"
)
// MapAuthStore stores identities in a map in the process.
// Great for testing but you should probably use some database
// to store these in a production environment.
type MapAuthStore struct {
store *sync.Map
}
// NewMapAuthStore inits the internal map
func NewMapAuthStore() *MapAuthStore {
return &MapAuthStore{&sync.Map{}}
}
// FindIdentity implements AuthStore
func (m *MapAuthStore) FindIdentity(idk string) (*SqrlIdentity, error) {
if knownUser, ok := m.store.Load(idk); ok {
log.Printf("Found existing identity: %#v", knownUser)
if identity, ok := knownUser.(*SqrlIdentity); ok {
return identity, nil
}
return nil, fmt.Errorf("Wrong type for identity %t", knownUser)
}
return nil, ErrNotFound
}
// SaveIdentity implements AuthStore
func (m *MapAuthStore) SaveIdentity(identity *SqrlIdentity) error {
m.store.Store(identity.Idk, identity)
return nil
}
// DeleteIdentity implements AuthStore
func (m *MapAuthStore) DeleteIdentity(idk string) error {
m.store.Delete(idk)
return nil
}