Skip to content

Commit def05ea

Browse files
committed
fix: update session grants in the auth code token endpoint handler
Callers may wish to see the granted scope and audience of a auth code flow updated by the token endpoint handler, before responding to the token request. Move calls to set the granted scope and audience from `AuthorizeExplicitGrantHandler.PopulateTokenEndpointResponse` to the `AuthorizeExplicitGrantHandler.HandleTokenEndpointRequest` method. Fix [ory/hydra#3969](ory/hydra#3969).
1 parent 8052806 commit def05ea

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

handler/oauth2/flow_authorize_code_token.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ func (c *AuthorizeExplicitGrantHandler) HandleTokenEndpointRequest(ctx context.C
6464

6565
// Override scopes
6666
request.SetRequestedScopes(authorizeRequest.GetRequestedScopes())
67+
for _, scope := range authorizeRequest.GetGrantedScopes() {
68+
request.GrantScope(scope)
69+
}
6770

6871
// Override audiences
6972
request.SetRequestedAudience(authorizeRequest.GetRequestedAudience())
73+
for _, audience := range authorizeRequest.GetGrantedAudience() {
74+
request.GrantAudience(audience)
75+
}
7076

7177
// The authorization server MUST ensure that the authorization code was issued to the authenticated
7278
// confidential client, or if the client is public, ensure that the
@@ -131,14 +137,6 @@ func (c *AuthorizeExplicitGrantHandler) PopulateTokenEndpointResponse(ctx contex
131137
return errorsx.WithStack(fosite.ErrInvalidRequest.WithWrap(err).WithDebug(err.Error()))
132138
}
133139

134-
for _, scope := range authorizeRequest.GetGrantedScopes() {
135-
requester.GrantScope(scope)
136-
}
137-
138-
for _, audience := range authorizeRequest.GetGrantedAudience() {
139-
requester.GrantAudience(audience)
140-
}
141-
142140
access, accessSignature, err := c.AccessTokenStrategy.GenerateAccessToken(ctx, requester)
143141
if err != nil {
144142
return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))

0 commit comments

Comments
 (0)