diff --git a/handlers/google_auth.go b/handlers/google_auth.go index fa1d3af..e3bf4b7 100644 --- a/handlers/google_auth.go +++ b/handlers/google_auth.go @@ -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 {