added redirect_uri fetching from query param

This commit is contained in:
2026-01-07 13:21:21 +08:00
parent ec18a6cacd
commit d91e4e57c8
+22 -4
View File
@@ -151,6 +151,7 @@ func checkUserAuthorization(userID, accessToken string) (bool, error) {
}
func GoogleLogin(w http.ResponseWriter, r *http.Request) {
helper.LogInfo(fmt.Sprintf("Generated oauth_state: %s", oauthStateString))
isSecure := strings.HasPrefix(os.Getenv("BACKEND_URL"), HTTPS)
@@ -314,10 +315,27 @@ 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,
})
// 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)
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)
}
func validateState(w http.ResponseWriter, r *http.Request) bool {