@@ -80,18 +80,39 @@ func AuthorizeHandler() gin.HandlerFunc {
8080 // used for response mode query or fragment
8181 loginState := "state=" + state + "&scope=" + strings .Join (scope , " " ) + "&redirect_uri=" + redirectURI
8282 loginURL := "/app?" + loginState
83+
8384 if responseMode == constants .ResponseModeFragment {
8485 loginURL = "/app#" + loginState
8586 }
8687
88+ if state == "" {
89+ handleResponse (gc , responseMode , loginURL , redirectURI , map [string ]interface {}{
90+ "type" : "authorization_response" ,
91+ "response" : map [string ]interface {}{
92+ "error" : "state_required" ,
93+ "error_description" : "state is required" ,
94+ },
95+ }, http .StatusOK )
96+ return
97+ }
98+
99+ if responseType == constants .ResponseTypeCode && codeChallenge == "" {
100+ handleResponse (gc , responseMode , loginURL , redirectURI , map [string ]interface {}{
101+ "type" : "authorization_response" ,
102+ "response" : map [string ]interface {}{
103+ "error" : "code_challenge_required" ,
104+ "error_description" : "code challenge is required" ,
105+ },
106+ }, http .StatusOK )
107+ }
108+
87109 loginError := map [string ]interface {}{
88110 "type" : "authorization_response" ,
89111 "response" : map [string ]interface {}{
90112 "error" : "login_required" ,
91113 "error_description" : "Login is required" ,
92114 },
93115 }
94-
95116 sessionToken , err := cookie .GetSession (gc )
96117 if err != nil {
97118 log .Debug ("GetSession failed: " , err )
@@ -274,10 +295,6 @@ func validateAuthorizeRequest(responseType, responseMode, clientID, state, codeC
274295 return fmt .Errorf ("invalid client_id %s" , clientID )
275296 }
276297
277- if strings .TrimSpace (state ) == "" {
278- return fmt .Errorf ("state is required" )
279- }
280-
281298 return nil
282299}
283300
0 commit comments