fixed logic
This commit is contained in:
+16
-17
@@ -165,6 +165,9 @@ func GoogleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
SameSite: http.SameSiteLaxMode,
|
||||
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)
|
||||
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.RespondWithJSON(w, http.StatusOK, map[string]string{
|
||||
// "message": "Authentication successful",
|
||||
// "access_token": accessToken,
|
||||
// })
|
||||
|
||||
// RedirectBaseURL := "com.ph.gov.psa.uess.dev:/"
|
||||
RedirectBaseURL := r.URL.Query().Get("redirect_uri")
|
||||
|
||||
if RedirectBaseURL == "" {
|
||||
helper.LogError(errors.New("missing redirect_uri"), "redirect_uri is missing in request")
|
||||
http.Error(w, "Missing redirect_uri", http.StatusBadRequest)
|
||||
RedirectURI := r.URL.Query().Get("redirect_uri")
|
||||
if RedirectURI != "" {
|
||||
if !IsAllowedRedirectURI(RedirectURI) {
|
||||
http.Error(w, "Invalid redirect_uri", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
RedirectURL := fmt.Sprintf("%s/callback?token=%s&user_id=%s", RedirectURI, accessToken, userID)
|
||||
http.Redirect(w, r, RedirectURL, http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
if !IsAllowedRedirectURI(RedirectBaseURL) {
|
||||
http.Error(w, "Invalid redirect_uri", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
RedirectURL := fmt.Sprintf("%s/callback?token=%s&user_id=%s", RedirectBaseURL, accessToken, userID)
|
||||
http.Redirect(w, r, RedirectURL, http.StatusSeeOther)
|
||||
// No redirect_uri provided, return JSON response
|
||||
helper.RespondWithJSON(w, http.StatusOK, map[string]string{
|
||||
"message": "Authentication successful",
|
||||
"access_token": accessToken,
|
||||
})
|
||||
}
|
||||
|
||||
func validateState(w http.ResponseWriter, r *http.Request) bool {
|
||||
|
||||
Reference in New Issue
Block a user