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

Set expires at for password credentials flow #210

Merged
merged 2 commits into from
Aug 21, 2017
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
3 changes: 3 additions & 0 deletions handler/oauth2/flow_resource_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oauth2

import (
"fmt"
"time"

"context"

Expand Down Expand Up @@ -50,6 +51,8 @@ func (c *ResourceOwnerPasswordCredentialsGrantHandler) HandleTokenEndpointReques

// Credentials must not be passed around, potentially leaking to the database!
delete(request.GetRequestForm(), "password")

request.GetSession().SetExpiresAt(fosite.AccessToken, time.Now().Add(c.AccessTokenLifespan))
return nil
}

Expand Down
9 changes: 8 additions & 1 deletion handler/oauth2/flow_resource_owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestResourceOwnerFlow_HandleTokenEndpointRequest(t *testing.T) {
store := internal.NewMockResourceOwnerPasswordCredentialsGrantStorage(ctrl)
defer ctrl.Finish()

areq := fosite.NewAccessRequest(nil)
areq := fosite.NewAccessRequest(new(fosite.DefaultSession))
areq.Form = url.Values{}

h := ResourceOwnerPasswordCredentialsGrantHandler{
Expand All @@ -32,6 +32,7 @@ func TestResourceOwnerFlow_HandleTokenEndpointRequest(t *testing.T) {
description string
setup func()
expectErr error
check func(areq *fosite.AccessRequest)
}{
{
description: "should fail because not responsible",
Expand Down Expand Up @@ -64,12 +65,18 @@ func TestResourceOwnerFlow_HandleTokenEndpointRequest(t *testing.T) {
setup: func() {
store.EXPECT().Authenticate(nil, "peter", "pan").Return(nil)
},
check: func(areq *fosite.AccessRequest) {
assert.NotEmpty(t, areq.GetSession().GetExpiresAt(fosite.AccessToken))
},
},
} {
c.setup()
err := h.HandleTokenEndpointRequest(nil, areq)
assert.True(t, errors.Cause(err) == c.expectErr, "(%d) %s\n%s\n%s", k, c.description, err, c.expectErr)
t.Logf("Passed test case %d", k)
if c.check != nil {
c.check(areq)
}
}
}

Expand Down