auth

Paddy 2014-09-18 Parent:1f7b44b130a0 Child:113ccb15b919

39:690561c6619a Go to Latest

auth/memstore.go

Include client updates and tests. Flesh out updating clients, and include unit tests to ensure that clientstores actually update appropriately. Add TODO comments where functionality is planned but stubbed out.

History
1 package auth
3 import (
4 "sync"
6 "secondbit.org/uuid"
7 )
9 type Memstore struct {
10 tokens map[string]Token
11 refreshTokenLookup map[string]string
12 profileTokenLookup map[string][]string
13 tokenLock sync.RWMutex
15 grants map[string]Grant
16 grantLock sync.RWMutex
18 clients map[string]Client
19 profileClientLookup map[string][]uuid.ID
20 clientLock sync.RWMutex
22 profiles map[string]Profile
23 profileLock sync.RWMutex
24 }
26 func NewMemstore() *Memstore {
27 return &Memstore{
28 tokens: map[string]Token{},
29 refreshTokenLookup: map[string]string{},
30 profileTokenLookup: map[string][]string{},
31 grants: map[string]Grant{},
32 clients: map[string]Client{},
33 profileClientLookup: map[string][]uuid.ID{},
34 profiles: map[string]Profile{},
35 }
36 }
38 func (m *Memstore) lookupTokenByRefresh(token string) (string, error) {
39 m.tokenLock.RLock()
40 defer m.tokenLock.RUnlock()
41 t, ok := m.refreshTokenLookup[token]
42 if !ok {
43 return "", ErrTokenNotFound
44 }
45 return t, nil
46 }
48 func (m *Memstore) lookupTokensByProfileID(id string) ([]string, error) {
49 m.tokenLock.RLock()
50 defer m.tokenLock.RUnlock()
51 return m.profileTokenLookup[id], nil
52 }
54 func (m *Memstore) lookupClientsByProfileID(id string) []uuid.ID {
55 m.clientLock.RLock()
56 defer m.clientLock.RUnlock()
57 c, ok := m.profileClientLookup[id]
58 if !ok {
59 return []uuid.ID{}
60 }
61 return c
62 }