auth
66:55d5107e8805
Go to Latest
auth/grant.go
Bugfixes and tests for getting grants.
Add tests for the grant confirmation part of the request to get a grant code.
When the request is denied, the redirect should have an access_denied error.
When the request is approved, the redirect should contain a code.
Fix numerous bugs in which the redirect URL didn't contain the parameters we
thought it would. Basically, anything that still used req.URL.Query().Set()
instead of copying the query, modifying it, and setting req.URL.RawQuery.
Fix a bug in which the redirectURL wasn't being properly set. Basically, when we
moved the redirectURI processing to the top of the file (c29c7df35905 for those
who forgot), we didn't update the reference to it lower in the file, where
redirectURI was being updated and we expected that to be reflected in the
processing.
The HTTP handler for getting grant codes is now completely tested except for
returning internal errors, which requires a new test harness be built to provoke
internal errors on demand. At this point, however, I'd like to continue on
implementing endpoints.
7 "code.secondbit.org/uuid"
11 // ErrNoGrantStore is returned when a Context tries to act on a grantStore without setting one first.
12 ErrNoGrantStore = errors.New("no grantStore was specified for the Context")
13 // ErrGrantNotFound is returned when a Grant is requested but not found in the grantStore.
14 ErrGrantNotFound = errors.New("grant not found in grantStore")
15 // ErrGrantAlreadyExists is returned when a Grant is added to a grantStore, but another Grant with the
16 // same Code already exists in the grantStore.
17 ErrGrantAlreadyExists = errors.New("grant already exists in grantStore")
20 // Grant represents an authorization grant made by a user to a Client, to
21 // access user data within a defined Scope for a limited amount of time.
32 type grantStore interface {
33 getGrant(code string) (Grant, error)
34 saveGrant(grant Grant) error
35 deleteGrant(code string) error
38 func (m *memstore) getGrant(code string) (Grant, error) {
40 defer m.grantLock.RUnlock()
41 grant, ok := m.grants[code]
43 return Grant{}, ErrGrantNotFound
48 func (m *memstore) saveGrant(grant Grant) error {
50 defer m.grantLock.Unlock()
51 _, ok := m.grants[grant.Code]
53 return ErrGrantAlreadyExists
55 m.grants[grant.Code] = grant
59 func (m *memstore) deleteGrant(code string) error {
61 defer m.grantLock.Unlock()
62 _, ok := m.grants[code]
64 return ErrGrantNotFound
66 delete(m.grants, code)