Skip to content

Commit

Permalink
fix: properly propagate request ID (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivshankar authored Feb 13, 2024
1 parent 0c340c4 commit 9b98b55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions handler/oauth2/flow_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (c *RefreshTokenGrantHandler) HandleTokenEndpointRequest(ctx context.Contex
return errorsx.WithStack(fosite.ErrInvalidGrant.WithHint("The OAuth 2.0 Client ID from this request does not match the ID during the initial token issuance."))
}

request.SetID(originalRequest.GetID())
request.SetSession(originalRequest.GetSession().Clone())
request.SetRequestedScopes(originalRequest.GetRequestedScopes())
request.SetRequestedAudience(originalRequest.GetRequestedAudience())
Expand Down
5 changes: 5 additions & 0 deletions handler/oauth2/flow_refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func TestRefreshFlow_HandleTokenEndpointRequest(t *testing.T) {
require.NoError(t, err)

areq.Form.Add("refresh_token", token)

orReqID := areq.GetID() + "_OR"
areq.Form.Add("or_request_id", orReqID)
err = store.CreateRefreshTokenSession(context.Background(), sig, &fosite.Request{
ID: orReqID,
Client: areq.Client,
GrantedScope: fosite.Arguments{"foo", "offline"},
RequestedScope: fosite.Arguments{"foo", "bar", "offline"},
Expand All @@ -177,6 +181,7 @@ func TestRefreshFlow_HandleTokenEndpointRequest(t *testing.T) {
assert.NotEqual(t, url.Values{"foo": []string{"bar"}}, areq.Form)
assert.Equal(t, time.Now().Add(time.Hour).UTC().Round(time.Second), areq.GetSession().GetExpiresAt(fosite.AccessToken))
assert.Equal(t, time.Now().Add(time.Hour).UTC().Round(time.Second), areq.GetSession().GetExpiresAt(fosite.RefreshToken))
assert.EqualValues(t, areq.Form.Get("or_request_id"), areq.GetID(), "Requester ID should be replaced based on the refresh token session")
},
},
{
Expand Down

0 comments on commit 9b98b55

Please sign in to comment.