Skip to content

Commit

Permalink
fix: wrap authorize response in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed May 7, 2024
1 parent d5eee06 commit c5ba343
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,31 +1126,36 @@ func (h *Handler) oAuth2Authorize(w http.ResponseWriter, r *http.Request, _ http
claims.Add("sid", session.ConsentRequest.LoginSessionID)

// done
response, err := h.r.OAuth2Provider().NewAuthorizeResponse(ctx, authorizeRequest, &Session{
DefaultSession: &openid.DefaultSession{
Claims: claims,
Headers: &jwt.Headers{Extra: map[string]interface{}{
// required for lookup on jwk endpoint
"kid": openIDKeyID,
}},
Subject: session.ConsentRequest.Subject,
},
Extra: session.Session.AccessToken,
KID: accessTokenKeyID,
ClientID: authorizeRequest.GetClient().GetID(),
ConsentChallenge: session.ID,
ExcludeNotBeforeClaim: h.c.ExcludeNotBeforeClaim(ctx),
AllowedTopLevelClaims: h.c.AllowedTopLevelClaims(ctx),
MirrorTopLevelClaims: h.c.MirrorTopLevelClaims(ctx),
Flow: flow,
})
if err != nil {
if err := h.r.Persister().Transaction(ctx, func(ctx context.Context, _ *pop.Connection) error {
response, err := h.r.OAuth2Provider().NewAuthorizeResponse(ctx, authorizeRequest, &Session{
DefaultSession: &openid.DefaultSession{
Claims: claims,
Headers: &jwt.Headers{Extra: map[string]interface{}{
// required for lookup on jwk endpoint
"kid": openIDKeyID,
}},
Subject: session.ConsentRequest.Subject,
},
Extra: session.Session.AccessToken,
KID: accessTokenKeyID,
ClientID: authorizeRequest.GetClient().GetID(),
ConsentChallenge: session.ID,
ExcludeNotBeforeClaim: h.c.ExcludeNotBeforeClaim(ctx),
AllowedTopLevelClaims: h.c.AllowedTopLevelClaims(ctx),
MirrorTopLevelClaims: h.c.MirrorTopLevelClaims(ctx),
Flow: flow,
})
if err != nil {
return err
}

h.r.OAuth2Provider().WriteAuthorizeResponse(ctx, w, authorizeRequest, response)
return nil
}); err != nil {
x.LogError(r, err, h.r.Logger())
h.writeAuthorizeError(w, r, authorizeRequest, err)
return
}

h.r.OAuth2Provider().WriteAuthorizeResponse(ctx, w, authorizeRequest, response)
}

// Delete OAuth 2.0 Access Token Parameters
Expand Down

0 comments on commit c5ba343

Please sign in to comment.