Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various bugfixes #123

Merged
merged 4 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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