auth
auth/memstore.go
Implement GrantStore for Memstore. Fix bug in GrantStore that asks for a UUID when it really wants a string. Implement GrantStore interface in Memstore, including unit tests for successful (i.e., works-as-intended) scenarios.
1 package auth
3 import "sync"
5 type Memstore struct {
6 tokens map[string]Token
7 refreshTokenLookup map[string]string
8 profileTokenLookup map[string][]string
9 tokenLock sync.RWMutex
11 grants map[string]Grant
12 grantLock sync.RWMutex
13 }
15 func NewMemstore() *Memstore {
16 return &Memstore{
17 tokens: map[string]Token{},
18 refreshTokenLookup: map[string]string{},
19 profileTokenLookup: map[string][]string{},
20 grants: map[string]Grant{},
21 }
22 }
24 func (m *Memstore) lookupTokenByRefresh(token string) (string, error) {
25 m.tokenLock.RLock()
26 defer m.tokenLock.RUnlock()
27 t, ok := m.refreshTokenLookup[token]
28 if !ok {
29 return "", ErrTokenNotFound
30 }
31 return t, nil
32 }
34 func (m *Memstore) lookupTokensByProfileID(id string) ([]string, error) {
35 m.tokenLock.RLock()
36 defer m.tokenLock.RUnlock()
37 return m.profileTokenLookup[id], nil
38 }