|
|
@@ -68,6 +68,15 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log := log.WithFields(log.Fields{
|
|
|
|
|
|
|
|
"response_mode": responseMode,
|
|
|
|
|
|
|
|
"response_type": responseType,
|
|
|
|
|
|
|
|
"state": state,
|
|
|
|
|
|
|
|
"code_challenge": codeChallenge,
|
|
|
|
|
|
|
|
"scope": scope,
|
|
|
|
|
|
|
|
"redirect_uri": redirectURI,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
@@ -76,8 +85,11 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loginError := map[string]interface{}{
|
|
|
|
loginError := map[string]interface{}{
|
|
|
|
"error": "login_required",
|
|
|
|
"type": "authorization_response",
|
|
|
|
"error_description": "Login is required",
|
|
|
|
"response": map[string]string{
|
|
|
|
|
|
|
|
"error": "login_required",
|
|
|
|
|
|
|
|
"error_description": "Login is required",
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sessionToken, err := cookie.GetSession(gc)
|
|
|
|
sessionToken, err := cookie.GetSession(gc)
|
|
|
@@ -99,8 +111,11 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("GetUserByID failed: ", err)
|
|
|
|
log.Debug("GetUserByID failed: ", err)
|
|
|
|
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
|
|
|
|
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
|
|
|
|
"error": "signup_required",
|
|
|
|
"type": "authorization_response",
|
|
|
|
"error_description": "Sign up required",
|
|
|
|
"response": map[string]string{
|
|
|
|
|
|
|
|
"error": "signup_required",
|
|
|
|
|
|
|
|
"error_description": "Sign up required",
|
|
|
|
|
|
|
|
},
|
|
|
|
}, http.StatusOK)
|
|
|
|
}, http.StatusOK)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -137,29 +152,37 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
|
|
// in case, response type is code and user is already logged in send the code and state
|
|
|
|
// in case, response type is code and user is already logged in send the code and state
|
|
|
|
// and cookie session will already be rolled over and set
|
|
|
|
// and cookie session will already be rolled over and set
|
|
|
|
if responseMode == constants.ResponseModeFormPost {
|
|
|
|
// gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
|
|
|
|
gc.HTML(http.StatusOK, authorizeFormPostTemplate, gin.H{
|
|
|
|
// "target_origin": redirectURI,
|
|
|
|
"target_origin": redirectURI,
|
|
|
|
// "authorization_response": map[string]interface{}{
|
|
|
|
"authorization_response": map[string]interface{}{
|
|
|
|
// "type": "authorization_response",
|
|
|
|
"type": "authorization_response",
|
|
|
|
// "response": map[string]string{
|
|
|
|
"response": map[string]string{
|
|
|
|
// "code": code,
|
|
|
|
"code": code,
|
|
|
|
// "state": state,
|
|
|
|
"state": state,
|
|
|
|
// },
|
|
|
|
},
|
|
|
|
// },
|
|
|
|
},
|
|
|
|
// })
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// params := "code=" + code + "&state=" + state
|
|
|
|
gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
|
|
|
|
|
|
|
|
"target_origin": redirectURI,
|
|
|
|
// if responseMode == constants.ResponseModeQuery {
|
|
|
|
"authorization_response": map[string]interface{}{
|
|
|
|
// if strings.Contains(redirectURI, "?") {
|
|
|
|
"type": "authorization_response",
|
|
|
|
// redirectURI = redirectURI + "&" + params
|
|
|
|
"response": map[string]string{
|
|
|
|
// } else {
|
|
|
|
"code": code,
|
|
|
|
// redirectURI = redirectURI + "?" + params
|
|
|
|
"state": state,
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
// } else if responseMode == constants.ResponseModeFragment {
|
|
|
|
},
|
|
|
|
// if strings.Contains(redirectURI, "#") {
|
|
|
|
})
|
|
|
|
// redirectURI = redirectURI + "&" + params
|
|
|
|
}
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// redirectURI = redirectURI + "#" + params
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
|
|
|
|
|
|
|
|
"code": code,
|
|
|
|
|
|
|
|
"state": state,
|
|
|
|
|
|
|
|
}, http.StatusOK)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -261,10 +284,8 @@ func validateAuthorizeRequest(responseType, responseMode, clientID, state, codeC
|
|
|
|
|
|
|
|
|
|
|
|
func handleResponse(gc *gin.Context, responseMode, loginURI, redirectURI string, data map[string]interface{}, httpStatusCode int) {
|
|
|
|
func handleResponse(gc *gin.Context, responseMode, loginURI, redirectURI string, data map[string]interface{}, httpStatusCode int) {
|
|
|
|
isAuthenticationRequired := false
|
|
|
|
isAuthenticationRequired := false
|
|
|
|
if val, ok := data["error"]; ok {
|
|
|
|
if _, ok := data["error"]; ok {
|
|
|
|
if val == "login_required" || val == "signup_required" {
|
|
|
|
isAuthenticationRequired = true
|
|
|
|
isAuthenticationRequired = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch responseMode {
|
|
|
|
switch responseMode {
|
|
|
|