auth

Paddy 2014-10-22 Parent:73a9f7a6af54 Child:e45bfa2abc00

54:0f80a3e391b8 Go to Latest

auth/grant.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
paddy@26 1 package auth
paddy@26 2
paddy@26 3 import (
paddy@29 4 "errors"
paddy@26 5 "time"
paddy@26 6
paddy@45 7 "code.secondbit.org/uuid"
paddy@26 8 )
paddy@26 9
paddy@29 10 var (
paddy@49 11 ErrNoGrantStore = errors.New("no GrantStore was specified for the Context")
paddy@49 12 ErrGrantNotFound = errors.New("grant not found in GrantStore")
paddy@49 13 ErrGrantAlreadyExists = errors.New("grant already exists in GrantStore")
paddy@29 14 )
paddy@29 15
paddy@26 16 type Grant struct {
paddy@26 17 Code string
paddy@26 18 Created time.Time
paddy@26 19 ExpiresIn int32
paddy@26 20 ClientID uuid.ID
paddy@26 21 Scope string
paddy@26 22 RedirectURI string
paddy@26 23 State string
paddy@26 24 }
paddy@26 25
paddy@26 26 type GrantStore interface {
paddy@26 27 GetGrant(code string) (Grant, error)
paddy@26 28 SaveGrant(grant Grant) error
paddy@29 29 DeleteGrant(code string) error
paddy@26 30 }
paddy@29 31
paddy@29 32 func (m *Memstore) GetGrant(code string) (Grant, error) {
paddy@29 33 m.grantLock.RLock()
paddy@29 34 defer m.grantLock.RUnlock()
paddy@29 35 grant, ok := m.grants[code]
paddy@29 36 if !ok {
paddy@29 37 return Grant{}, ErrGrantNotFound
paddy@29 38 }
paddy@29 39 return grant, nil
paddy@29 40 }
paddy@29 41
paddy@29 42 func (m *Memstore) SaveGrant(grant Grant) error {
paddy@29 43 m.grantLock.Lock()
paddy@29 44 defer m.grantLock.Unlock()
paddy@29 45 _, ok := m.grants[grant.Code]
paddy@29 46 if ok {
paddy@29 47 return ErrGrantAlreadyExists
paddy@29 48 }
paddy@29 49 m.grants[grant.Code] = grant
paddy@29 50 return nil
paddy@29 51 }
paddy@29 52
paddy@29 53 func (m *Memstore) DeleteGrant(code string) error {
paddy@29 54 m.grantLock.Lock()
paddy@29 55 defer m.grantLock.Unlock()
paddy@29 56 _, ok := m.grants[code]
paddy@29 57 if !ok {
paddy@29 58 return ErrGrantNotFound
paddy@29 59 }
paddy@29 60 delete(m.grants, code)
paddy@29 61 return nil
paddy@29 62 }