auth

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

55:cfab12566289 Go to Latest

auth/grant.go

Update Context with new CheckEndpoint and CountEndpoints. Update the Context.CheckEndpoint method to pass through the new "strict" parameter that controls how URLs are checked for validation. Add a Context.CountEndpoints method to safely access the number of endpoints in stored for the client in the associent ClientStore. Finally, remove the error return from Context.Render, as we'd only ever want to log that, anyways. So we may as well just log it from the central function.

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