|
|
|
@@ -86,7 +86,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
loginError := map[string]interface{}{
|
|
|
|
|
"type": "authorization_response",
|
|
|
|
|
"response": map[string]string{
|
|
|
|
|
"response": map[string]interface{}{
|
|
|
|
|
"error": "login_required",
|
|
|
|
|
"error_description": "Login is required",
|
|
|
|
|
},
|
|
|
|
@@ -106,13 +106,14 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
|
handleResponse(gc, responseMode, loginURL, redirectURI, loginError, http.StatusOK)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userID := claims.Subject
|
|
|
|
|
user, err := db.Provider.GetUserByID(gc, userID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Debug("GetUserByID failed: ", err)
|
|
|
|
|
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
|
|
|
|
|
"type": "authorization_response",
|
|
|
|
|
"response": map[string]string{
|
|
|
|
|
"response": map[string]interface{}{
|
|
|
|
|
"error": "signup_required",
|
|
|
|
|
"error_description": "Sign up required",
|
|
|
|
|
},
|
|
|
|
@@ -152,37 +153,39 @@ func AuthorizeHandler() gin.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
|
|
|
|
|
"target_origin": redirectURI,
|
|
|
|
|
"authorization_response": map[string]interface{}{
|
|
|
|
|
// gc.HTML(http.StatusOK, authorizeWebMessageTemplate, gin.H{
|
|
|
|
|
// "target_origin": redirectURI,
|
|
|
|
|
// "authorization_response": map[string]interface{}{
|
|
|
|
|
// "type": "authorization_response",
|
|
|
|
|
// "response": map[string]string{
|
|
|
|
|
// "code": code,
|
|
|
|
|
// "state": state,
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
params := "code=" + code + "&state=" + state
|
|
|
|
|
if responseMode == constants.ResponseModeQuery {
|
|
|
|
|
if strings.Contains(redirectURI, "?") {
|
|
|
|
|
redirectURI = redirectURI + "&" + params
|
|
|
|
|
} else {
|
|
|
|
|
redirectURI = redirectURI + "?" + params
|
|
|
|
|
}
|
|
|
|
|
} else if responseMode == constants.ResponseModeFragment {
|
|
|
|
|
if strings.Contains(redirectURI, "#") {
|
|
|
|
|
redirectURI = redirectURI + "&" + params
|
|
|
|
|
} else {
|
|
|
|
|
redirectURI = redirectURI + "#" + params
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
|
|
|
|
|
"type": "authorization_response",
|
|
|
|
|
"response": map[string]string{
|
|
|
|
|
"response": map[string]interface{}{
|
|
|
|
|
"code": code,
|
|
|
|
|
"state": state,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// params := "code=" + code + "&state=" + state
|
|
|
|
|
|
|
|
|
|
// if responseMode == constants.ResponseModeQuery {
|
|
|
|
|
// if strings.Contains(redirectURI, "?") {
|
|
|
|
|
// redirectURI = redirectURI + "&" + params
|
|
|
|
|
// } else {
|
|
|
|
|
// redirectURI = redirectURI + "?" + params
|
|
|
|
|
// }
|
|
|
|
|
// } 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)
|
|
|
|
|
}, http.StatusOK)
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@@ -284,7 +287,7 @@ func validateAuthorizeRequest(responseType, responseMode, clientID, state, codeC
|
|
|
|
|
|
|
|
|
|
func handleResponse(gc *gin.Context, responseMode, loginURI, redirectURI string, data map[string]interface{}, httpStatusCode int) {
|
|
|
|
|
isAuthenticationRequired := false
|
|
|
|
|
if _, ok := data["error"]; ok {
|
|
|
|
|
if _, ok := data["response"].(map[string]interface{})["error"]; ok {
|
|
|
|
|
isAuthenticationRequired = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -305,7 +308,7 @@ func handleResponse(gc *gin.Context, responseMode, loginURI, redirectURI string,
|
|
|
|
|
case constants.ResponseModeFormPost:
|
|
|
|
|
gc.HTML(httpStatusCode, authorizeFormPostTemplate, gin.H{
|
|
|
|
|
"target_origin": redirectURI,
|
|
|
|
|
"authorization_response": data,
|
|
|
|
|
"authorization_response": data["response"],
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|