Skip to content

Commit

Permalink
Revert to use client_id and redirect_uri in consent URL
Browse files Browse the repository at this point in the history
  • Loading branch information
louischan-oursky committed Mar 6, 2024
1 parent 3fbd8b5 commit dadf4dd
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions pkg/lib/oauth/handler/handler_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (h *AuthorizationHandler) HandleConsentWithUserCancel(req *http.Request) ht
var resultErr httputil.Result

if errors.As(err, &oauthError) {
resultErr = h.prepareConsentErrInvalidOAuthResponse(consentRequest, *oauthError)
resultErr = h.prepareConsentErrInvalidOAuthResponse(req, *oauthError)
} else {
h.Logger.WithError(err).Error("authz handler failed")
resultErr = authorizationResultError{
Expand Down Expand Up @@ -230,7 +230,7 @@ func (h *AuthorizationHandler) doHandleConsent(req *http.Request, withUserConsen
var resultErr httputil.Result

if errors.As(err, &oauthError) {
resultErr = h.prepareConsentErrInvalidOAuthResponse(consentRequest, *oauthError)
resultErr = h.prepareConsentErrInvalidOAuthResponse(req, *oauthError)
} else {
h.Logger.WithError(err).Error("authz handler failed")
resultErr = authorizationResultError{
Expand Down Expand Up @@ -665,26 +665,23 @@ func (h *AuthorizationHandler) generateSettingsActionResponse(
return nil
}

func (h *AuthorizationHandler) prepareConsentErrInvalidOAuthResponse(consent *consentRequest, oauthError protocol.OAuthProtocolError) httputil.Result {
func (h *AuthorizationHandler) prepareConsentErrInvalidOAuthResponse(req *http.Request, oauthError protocol.OAuthProtocolError) httputil.Result {
resultErr := authorizationResultError{
Response: oauthError.Response,
RedirectURI: consent.RedirectURI,
Response: oauthError.Response,
}

client := h.ClientResolver.ResolveClient(req.URL.Query().Get("client_id"))

// Only redirect if oauth session is expired / not found
// It mostly happens when user refresh the page or go back to the page after authenication
if oauthError.Type() != "invalid_request" {
return resultErr
}

client := h.ClientResolver.ResolveClient(consent.Client.ClientID)
if client == nil {
return resultErr
}

err := validateRedirectURI(client, h.HTTPProto, h.HTTPOrigin, h.AppDomains, consent.RedirectURI)
if err != nil {
return resultErr
if oauthError.Type() == "invalid_request" && client != nil {
redirectURI, err := url.Parse(req.URL.Query().Get("redirect_uri"))
if err == nil {
err = validateRedirectURI(client, h.HTTPProto, h.HTTPOrigin, h.AppDomains, redirectURI)
if err == nil {
resultErr.RedirectURI = redirectURI
}
}
}

return resultErr
Expand Down

0 comments on commit dadf4dd

Please sign in to comment.