Skip to content

Commit

Permalink
Remove variable shadowing for oauth error response return authgear#3813
Browse files Browse the repository at this point in the history
  • Loading branch information
IniZio committed Mar 4, 2024
1 parent 71cbbd3 commit 65db697
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions pkg/lib/oauth/handler/handler_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,21 @@ func (h *AuthorizationHandler) HandleConsentWithUserCancel(req *http.Request) ht
consentRequest, err := h.prepareConsentRequest(req)
if err != nil {
var oauthError *protocol.OAuthProtocolError
resultErr := authorizationResultError{
// Don't redirect for those unexpected errors
// e.g. oauth session expire or invalid client_id, redirect_uri
RedirectURI: nil,
}
var resultErr httputil.Result

if errors.As(err, &oauthError) {
resultErr := h.prepareErrInvalidOAuthResponse(req, *oauthError)
return resultErr
resultErr = h.prepareErrInvalidOAuthResponse(req, *oauthError)
} else {
h.Logger.WithError(err).Error("authz handler failed")
resultErr.Response = protocol.NewErrorResponse("server_error", "internal server error")
resultErr.InternalError = true
resultErr = authorizationResultError{
// Don't redirect for those unexpected errors
// e.g. oauth session expire or invalid client_id, redirect_uri
RedirectURI: nil,
Response: protocol.NewErrorResponse("server_error", "internal server error"),
InternalError: true,
}
}

return resultErr
}

Expand Down Expand Up @@ -236,19 +238,21 @@ func (h *AuthorizationHandler) doHandleConsent(req *http.Request, withUserConsen

if err != nil {
var oauthError *protocol.OAuthProtocolError
resultErr := authorizationResultError{
// Don't redirect for those unexpected errors
// e.g. oauth session expire or invalid client_id, redirect_uri
RedirectURI: nil,
}
var resultErr httputil.Result

if errors.As(err, &oauthError) {
resultErr := h.prepareErrInvalidOAuthResponse(req, *oauthError)
return resultErr, nil
resultErr = h.prepareErrInvalidOAuthResponse(req, *oauthError)
} else {
h.Logger.WithError(err).Error("authz handler failed")
resultErr.Response = protocol.NewErrorResponse("server_error", "internal server error")
resultErr.InternalError = true
resultErr = authorizationResultError{
// Don't redirect for those unexpected errors
// e.g. oauth session expire or invalid client_id, redirect_uri
RedirectURI: nil,
Response: protocol.NewErrorResponse("server_error", "internal server error"),
InternalError: true,
}
}

return resultErr, nil
}

Expand Down

0 comments on commit 65db697

Please sign in to comment.