auth

Paddy 2014-10-22 Parent:3a6a65ed380c Child:e45bfa2abc00

54:0f80a3e391b8 Go to Latest

auth/memstore.go

Update CheckEndpoints for strict checking, add CountEndpoints. Create a "strict" mode for CheckEndpoints that will only return true on an exact match, and update the memstore implementation accordingly. Add tests to make sure that the strict mode is adhered to. We need this mode because in certain situations (e.g., the client has more than one endpoint registered), the spec demands a full-string comparison. Add a CountEndpoints method to the ClientStore that will return the number of endpoints registered for a specific client. As we just mentioned, the rules for how a redirect URI is validated depend upon the number of endpoints a client has registered, so we need to be able to get at that number.

History
1 package auth
3 import (
4 "sync"
6 "code.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 endpoints map[string][]Endpoint
23 endpointLock sync.RWMutex
25 profiles map[string]Profile
26 profileLock sync.RWMutex
28 logins map[string]Login
29 profileLoginLookup map[string][]string
30 loginLock sync.RWMutex
31 }
33 func NewMemstore() *Memstore {
34 return &Memstore{
35 tokens: map[string]Token{},
36 refreshTokenLookup: map[string]string{},
37 profileTokenLookup: map[string][]string{},
38 grants: map[string]Grant{},
39 clients: map[string]Client{},
40 profileClientLookup: map[string][]uuid.ID{},
41 endpoints: map[string][]Endpoint{},
42 profiles: map[string]Profile{},
43 logins: map[string]Login{},
44 profileLoginLookup: map[string][]string{},
45 }
46 }
48 func (m *Memstore) lookupTokenByRefresh(token string) (string, error) {
49 m.tokenLock.RLock()
50 defer m.tokenLock.RUnlock()
51 t, ok := m.refreshTokenLookup[token]
52 if !ok {
53 return "", ErrTokenNotFound
54 }
55 return t, nil
56 }
58 func (m *Memstore) lookupTokensByProfileID(id string) ([]string, error) {
59 m.tokenLock.RLock()
60 defer m.tokenLock.RUnlock()
61 return m.profileTokenLookup[id], nil
62 }
64 func (m *Memstore) lookupClientsByProfileID(id string) []uuid.ID {
65 m.clientLock.RLock()
66 defer m.clientLock.RUnlock()
67 c, ok := m.profileClientLookup[id]
68 if !ok {
69 return []uuid.ID{}
70 }
71 return c
72 }