fixed logic
This commit is contained in:
+16
-17
@@ -165,6 +165,9 @@ func GoogleLogin(w http.ResponseWriter, r *http.Request) {
|
|||||||
SameSite: http.SameSiteLaxMode,
|
SameSite: http.SameSiteLaxMode,
|
||||||
Expires: time.Now().Add(5 * time.Minute),
|
Expires: time.Now().Add(5 * time.Minute),
|
||||||
})
|
})
|
||||||
|
// RedirectBaseURL := r.URL.Query().Get("redirect_uri")
|
||||||
|
// log.Print("RedirectBaseURL1111111 from query param: ", RedirectBaseURL)
|
||||||
|
|
||||||
url := googleOauthConfig.AuthCodeURL(oauthStateString, oauth2.AccessTypeOffline, oauth2.ApprovalForce)
|
url := googleOauthConfig.AuthCodeURL(oauthStateString, oauth2.AccessTypeOffline, oauth2.ApprovalForce)
|
||||||
http.Redirect(w, r, url, http.StatusFound)
|
http.Redirect(w, r, url, http.StatusFound)
|
||||||
}
|
}
|
||||||
@@ -315,27 +318,23 @@ func GoogleCallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
helper.LogInfo("Copy this access token: " + accessToken)
|
helper.LogInfo("Copy this access token: " + accessToken)
|
||||||
// helper.RespondWithJSON(w, http.StatusOK, map[string]string{
|
|
||||||
// "message": "Authentication successful",
|
|
||||||
// "access_token": accessToken,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// RedirectBaseURL := "com.ph.gov.psa.uess.dev:/"
|
RedirectURI := r.URL.Query().Get("redirect_uri")
|
||||||
RedirectBaseURL := r.URL.Query().Get("redirect_uri")
|
if RedirectURI != "" {
|
||||||
|
if !IsAllowedRedirectURI(RedirectURI) {
|
||||||
if RedirectBaseURL == "" {
|
http.Error(w, "Invalid redirect_uri", http.StatusBadRequest)
|
||||||
helper.LogError(errors.New("missing redirect_uri"), "redirect_uri is missing in request")
|
return
|
||||||
http.Error(w, "Missing redirect_uri", http.StatusBadRequest)
|
}
|
||||||
|
RedirectURL := fmt.Sprintf("%s/callback?token=%s&user_id=%s", RedirectURI, accessToken, userID)
|
||||||
|
http.Redirect(w, r, RedirectURL, http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsAllowedRedirectURI(RedirectBaseURL) {
|
// No redirect_uri provided, return JSON response
|
||||||
http.Error(w, "Invalid redirect_uri", http.StatusBadRequest)
|
helper.RespondWithJSON(w, http.StatusOK, map[string]string{
|
||||||
return
|
"message": "Authentication successful",
|
||||||
}
|
"access_token": accessToken,
|
||||||
|
})
|
||||||
RedirectURL := fmt.Sprintf("%s/callback?token=%s&user_id=%s", RedirectBaseURL, accessToken, userID)
|
|
||||||
http.Redirect(w, r, RedirectURL, http.StatusSeeOther)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateState(w http.ResponseWriter, r *http.Request) bool {
|
func validateState(w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user