Skip to content

Commit

Permalink
all: resolve rethinkdb and warden endpoint issues
Browse files Browse the repository at this point in the history
* rethinkdb: resolve an issue where missing refresh tokens cause duplicate key error

close #122

* warden: endpoint should only require valid client, not policy based access control

close #121

* consent: set expiry time to one hour

* warden: fix tests
  • Loading branch information
Aeneas authored Jun 27, 2016
1 parent c77d2dc commit ac7710d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
8 changes: 7 additions & 1 deletion internal/fosite_store_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ func (s *FositeMemoryStore) PersistAuthorizeCodeGrantSession(ctx context.Context
return err
} else if err := s.CreateAccessTokenSession(ctx, accessSignature, request); err != nil {
return err
} else if err := s.CreateRefreshTokenSession(ctx, refreshSignature, request); err != nil {
}

if refreshSignature == "" {
return nil
}

if err := s.CreateRefreshTokenSession(ctx, refreshSignature, request); err != nil {
return err
}

Expand Down
8 changes: 7 additions & 1 deletion internal/fosite_store_rethinkdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ func (s *FositeRehinkDBStore) PersistAuthorizeCodeGrantSession(ctx context.Conte
return err
} else if err := s.CreateAccessTokenSession(ctx, accessSignature, request); err != nil {
return err
} else if err := s.CreateRefreshTokenSession(ctx, refreshSignature, request); err != nil {
}

if refreshSignature == "" {
return nil
}

if err := s.CreateRefreshTokenSession(ctx, refreshSignature, request); err != nil {
return err
}

Expand Down
1 change: 1 addition & 0 deletions internal/fosite_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func TestCreateGetDeleteOpenIDConnectSession(t *testing.T) {
pkg.AssertError(t, true, err, "%s", k)
}
}

func TestCreateGetDeleteRefreshTokenSession(t *testing.T) {
ctx := context.Background()
for k, m := range clientManagers {
Expand Down
2 changes: 1 addition & 1 deletion oauth2/consent_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *DefaultConsentStrategy) ValidateResponse(a fosite.AuthorizeRequester, t
Subject: subject,
Issuer: s.Issuer,
IssuedAt: time.Now(),
ExpiresAt: time.Now(),
ExpiresAt: time.Now().Add(time.Hour),
Extra: t.Claims,
},
Headers: &ejwt.Headers{},
Expand Down
11 changes: 4 additions & 7 deletions warden/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (h *WardenHandler) SetRoutes(r *httprouter.Router) {

func (h *WardenHandler) Authorized(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
ctx := herodot.NewContext()
clientCtx, err := h.authorizeClient(ctx, w, r, "an:hydra:warden:authorized")
clientCtx, err := h.authorizeClient(ctx, w, r)
if err != nil {
h.H.WriteError(ctx, w, r, err)
return
Expand All @@ -87,7 +87,7 @@ func (h *WardenHandler) Authorized(w http.ResponseWriter, r *http.Request, _ htt

func (h *WardenHandler) Allowed(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
ctx := herodot.NewContext()
clientCtx, err := h.authorizeClient(ctx, w, r, "an:hydra:warden:allowed")
clientCtx, err := h.authorizeClient(ctx, w, r)
if err != nil {
h.H.WriteError(ctx, w, r, err)
return
Expand All @@ -109,11 +109,8 @@ func (h *WardenHandler) Allowed(w http.ResponseWriter, r *http.Request, _ httpro
h.H.Write(ctx, w, r, authContext)
}

func (h *WardenHandler) authorizeClient(ctx context.Context, w http.ResponseWriter, r *http.Request, action string) (*firewall.Context, error) {
authctx, err := h.Warden.ActionAllowed(ctx, TokenFromRequest(r), &ladon.Request{
Action: action,
Resource: "rn:hydra:warden",
}, "hydra.warden")
func (h *WardenHandler) authorizeClient(ctx context.Context, w http.ResponseWriter, r *http.Request) (*firewall.Context, error) {
authctx, err := h.Warden.Authorized(ctx, TokenFromRequest(r), "core")
if err != nil {
return nil, err
}
Expand Down
7 changes: 2 additions & 5 deletions warden/warden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ var ladonWarden = pkg.LadonWarden(map[string]ladon.Policy{
ID: "2",
Subjects: []string{"siri"},
Resources: []string{"<.*>"},
Actions: []string{
"an:hydra:warden:allowed",
"an:hydra:warden:authorized",
},
Actions: []string{},
Effect: ladon.AllowAccess,
},
})
Expand Down Expand Up @@ -79,7 +76,7 @@ func init() {
fositeStore.CreateAccessTokenSession(nil, tokens[0][0], ar)

ar = fosite.NewAccessRequest(&oauth2.Session{Subject: "siri"})
ar.GrantedScopes = fosite.Arguments{"hydra.warden"}
ar.GrantedScopes = fosite.Arguments{"core"}
fositeStore.CreateAccessTokenSession(nil, tokens[1][0], ar)

conf := &coauth2.Config{
Expand Down

0 comments on commit ac7710d

Please sign in to comment.