@@ -68,6 +68,15 @@ func AuthorizeHandler() gin.HandlerFunc {
6868 return
6969 }
7070
71+ log := log .WithFields (log.Fields {
72+ "response_mode" : responseMode ,
73+ "response_type" : responseType ,
74+ "state" : state ,
75+ "code_challenge" : codeChallenge ,
76+ "scope" : scope ,
77+ "redirect_uri" : redirectURI ,
78+ })
79+
7180 // used for response mode query or fragment
7281 loginState := "state=" + state + "&scope=" + strings .Join (scope , " " ) + "&redirect_uri=" + redirectURI
7382 loginURL := "/app?" + loginState
@@ -76,8 +85,11 @@ func AuthorizeHandler() gin.HandlerFunc {
7685 }
7786
7887 loginError := map [string ]interface {}{
79- "error" : "login_required" ,
80- "error_description" : "Login is required" ,
88+ "type" : "authorization_response" ,
89+ "response" : map [string ]string {
90+ "error" : "login_required" ,
91+ "error_description" : "Login is required" ,
92+ },
8193 }
8294
8395 sessionToken , err := cookie .GetSession (gc )
@@ -99,8 +111,11 @@ func AuthorizeHandler() gin.HandlerFunc {
99111 if err != nil {
100112 log .Debug ("GetUserByID failed: " , err )
101113 handleResponse (gc , responseMode , loginURL , redirectURI , map [string ]interface {}{
102- "error" : "signup_required" ,
103- "error_description" : "Sign up required" ,
114+ "type" : "authorization_response" ,
115+ "response" : map [string ]string {
116+ "error" : "signup_required" ,
117+ "error_description" : "Sign up required" ,
118+ },
104119 }, http .StatusOK )
105120 return
106121 }
@@ -137,50 +152,37 @@ func AuthorizeHandler() gin.HandlerFunc {
137152
138153 // in case, response type is code and user is already logged in send the code and state
139154 // and cookie session will already be rolled over and set
140- // if responseMode == constants.ResponseModeFormPost {
141- // gc.HTML(http.StatusOK, authorizeFormPostTemplate, gin.H{
142- // "target_origin": redirectURI,
143- // "authorization_response": map[string]interface{}{
144- // "type": "authorization_response",
145- // "response": map[string]string{
146- // "code": code,
147- // "state": state,
148- // },
149- // },
150- // })
151- // } else {
152- // gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
153- // "target_origin": redirectURI,
154- // "authorization_response": map[string]interface{}{
155- // "type": "authorization_response",
156- // "response": map[string]string{
157- // "code": code,
158- // "state": state,
159- // },
160- // },
161- // })
155+ gc .HTML (http .StatusOK , authorizeWebMessageTemplate , gin.H {
156+ "target_origin" : redirectURI ,
157+ "authorization_response" : map [string ]interface {}{
158+ "type" : "authorization_response" ,
159+ "response" : map [string ]string {
160+ "code" : code ,
161+ "state" : state ,
162+ },
163+ },
164+ })
165+
166+ // params := "code=" + code + "&state=" + state
167+
168+ // if responseMode == constants.ResponseModeQuery {
169+ // if strings.Contains(redirectURI, "?") {
170+ // redirectURI = redirectURI + "&" + params
171+ // } else {
172+ // redirectURI = redirectURI + "?" + params
173+ // }
174+ // } else if responseMode == constants.ResponseModeFragment {
175+ // if strings.Contains(redirectURI, "#") {
176+ // redirectURI = redirectURI + "&" + params
177+ // } else {
178+ // redirectURI = redirectURI + "#" + params
179+ // }
162180 // }
163181
164- params := "code=" + code + "&state=" + state
165-
166- if responseMode == constants .ResponseModeQuery {
167- if strings .Contains (redirectURI , "?" ) {
168- redirectURI = redirectURI + "&" + params
169- } else {
170- redirectURI = redirectURI + "?" + params
171- }
172- } else if responseMode == constants .ResponseModeFragment {
173- if strings .Contains (redirectURI , "#" ) {
174- redirectURI = redirectURI + "&" + params
175- } else {
176- redirectURI = redirectURI + "#" + params
177- }
178- }
179-
180- handleResponse (gc , responseMode , loginURL , redirectURI , map [string ]interface {}{
181- "code" : code ,
182- "state" : state ,
183- }, http .StatusOK )
182+ // handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
183+ // "code": code,
184+ // "state": state,
185+ // }, http.StatusOK)
184186
185187 return
186188 }
@@ -282,10 +284,8 @@ func validateAuthorizeRequest(responseType, responseMode, clientID, state, codeC
282284
283285func handleResponse (gc * gin.Context , responseMode , loginURI , redirectURI string , data map [string ]interface {}, httpStatusCode int ) {
284286 isAuthenticationRequired := false
285- if val , ok := data ["error" ]; ok {
286- if val == "login_required" || val == "signup_required" {
287- isAuthenticationRequired = true
288- }
287+ if _ , ok := data ["error" ]; ok {
288+ isAuthenticationRequired = true
289289 }
290290
291291 switch responseMode {
0 commit comments