fix(server): revert the state & code_challenge validation

This commit is contained in:
Lakhan Samani 2022-10-18 23:24:19 +05:30
parent 252cd1fa2d
commit c716638725

View File

@ -80,10 +80,32 @@ func AuthorizeHandler() gin.HandlerFunc {
// used for response mode query or fragment // used for response mode query or fragment
loginState := "state=" + state + "&scope=" + strings.Join(scope, " ") + "&redirect_uri=" + redirectURI loginState := "state=" + state + "&scope=" + strings.Join(scope, " ") + "&redirect_uri=" + redirectURI
loginURL := "/app?" + loginState loginURL := "/app?" + loginState
if responseMode == constants.ResponseModeFragment { if responseMode == constants.ResponseModeFragment {
loginURL = "/app#" + loginState loginURL = "/app#" + loginState
} }
if state == "" {
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
"type": "authorization_response",
"response": map[string]interface{}{
"error": "state_required",
"error_description": "state is required",
},
}, http.StatusOK)
return
}
if responseType == constants.ResponseTypeCode && codeChallenge == "" {
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
"type": "authorization_response",
"response": map[string]interface{}{
"error": "code_challenge_required",
"error_description": "code challenge is required",
},
}, http.StatusOK)
}
loginError := map[string]interface{}{ loginError := map[string]interface{}{
"type": "authorization_response", "type": "authorization_response",
"response": map[string]interface{}{ "response": map[string]interface{}{
@ -91,7 +113,6 @@ func AuthorizeHandler() gin.HandlerFunc {
"error_description": "Login is required", "error_description": "Login is required",
}, },
} }
sessionToken, err := cookie.GetSession(gc) sessionToken, err := cookie.GetSession(gc)
if err != nil { if err != nil {
log.Debug("GetSession failed: ", err) log.Debug("GetSession failed: ", err)
@ -274,10 +295,6 @@ func validateAuthorizeRequest(responseType, responseMode, clientID, state, codeC
return fmt.Errorf("invalid client_id %s", clientID) return fmt.Errorf("invalid client_id %s", clientID)
} }
if strings.TrimSpace(state) == "" {
return fmt.Errorf("state is required")
}
return nil return nil
} }