Skip to content

Commit

Permalink
fix: prevent accidentially returned token in tx error case
Browse files Browse the repository at this point in the history
In case the transaction commit fails, the responder reference was already modified which could result in a token returned which was not persisted.
  • Loading branch information
sja committed Oct 5, 2022
1 parent e98c0d7 commit 5ff808a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions handler/oauth2/flow_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ func (c *RefreshTokenGrantHandler) PopulateTokenEndpointResponse(ctx context.Con
return err
}

responder.SetAccessToken(accessToken)
responder.SetTokenType("bearer")
atLifespan := fosite.GetEffectiveLifespan(requester.GetClient(), fosite.GrantTypeRefreshToken, fosite.AccessToken, c.Config.GetAccessTokenLifespan(ctx))
responder.SetExpiresIn(getExpiresIn(requester, fosite.AccessToken, atLifespan, time.Now().UTC()))
responder.SetScopes(requester.GetGrantedScopes())
responder.SetExtra("refresh_token", refreshToken)

if err = storage.MaybeCommitTx(ctx, c.TokenRevocationStorage); err != nil {
return err
} else {
responder.SetAccessToken(accessToken)
responder.SetTokenType("bearer")
atLifespan := fosite.GetEffectiveLifespan(requester.GetClient(), fosite.GrantTypeRefreshToken, fosite.AccessToken, c.Config.GetAccessTokenLifespan(ctx))
responder.SetExpiresIn(getExpiresIn(requester, fosite.AccessToken, atLifespan, time.Now().UTC()))
responder.SetScopes(requester.GetGrantedScopes())
responder.SetExtra("refresh_token", refreshToken)
}

return nil
Expand Down

0 comments on commit 5ff808a

Please sign in to comment.