Compare commits

..

5 Commits

Author SHA1 Message Date
Lakhan Samani
eaa10ec5bc fix: error detection 2022-10-18 22:34:57 +05:30
Lakhan Samani
253128ca0c fix: query params for code response 2022-10-18 22:00:54 +05:30
Lakhan Samani
cddfe1e088 fix: response 2022-10-18 21:46:37 +05:30
Lakhan Samani
8e655bcb5b fix: authorize response 2022-10-18 21:29:09 +05:30
Lakhan Samani
9a411e673c fix: reponse 2022-10-18 21:08:53 +05:30

View File

@@ -68,6 +68,15 @@ func AuthorizeHandler() gin.HandlerFunc {
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
loginState := "state=" + state + "&scope=" + strings.Join(scope, " ") + "&redirect_uri=" + redirectURI
loginURL := "/app?" + loginState
@@ -76,8 +85,11 @@ func AuthorizeHandler() gin.HandlerFunc {
}
loginError := map[string]interface{}{
"error": "login_required",
"error_description": "Login is required",
"type": "authorization_response",
"response": map[string]string{
"error": "login_required",
"error_description": "Login is required",
},
}
sessionToken, err := cookie.GetSession(gc)
@@ -94,13 +106,17 @@ 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{}{
"error": "signup_required",
"error_description": "Sign up required",
"type": "authorization_response",
"response": map[string]string{
"error": "signup_required",
"error_description": "Sign up required",
},
}, http.StatusOK)
return
}
@@ -137,32 +153,18 @@ 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
// if responseMode == constants.ResponseModeFormPost {
// gc.HTML(http.StatusOK, authorizeFormPostTemplate, gin.H{
// "target_origin": redirectURI,
// "authorization_response": map[string]interface{}{
// "type": "authorization_response",
// "response": map[string]string{
// "code": code,
// "state": state,
// },
// 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,
// },
// })
// } else {
// 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
@@ -178,8 +180,11 @@ func AuthorizeHandler() gin.HandlerFunc {
}
handleResponse(gc, responseMode, loginURL, redirectURI, map[string]interface{}{
"code": code,
"state": state,
"type": "authorization_response",
"response": map[string]string{
"code": code,
"state": state,
},
}, http.StatusOK)
return
@@ -282,10 +287,8 @@ 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 val, ok := data["error"]; ok {
if val == "login_required" || val == "signup_required" {
isAuthenticationRequired = true
}
if _, ok := data["response"].(map[string]string)["error"]; ok {
isAuthenticationRequired = true
}
switch responseMode {