added redirect_uri fetching from query param
This commit is contained in:
+22
-4
@@ -151,6 +151,7 @@ func checkUserAuthorization(userID, accessToken string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GoogleLogin(w http.ResponseWriter, r *http.Request) {
|
func GoogleLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
helper.LogInfo(fmt.Sprintf("Generated oauth_state: %s", oauthStateString))
|
helper.LogInfo(fmt.Sprintf("Generated oauth_state: %s", oauthStateString))
|
||||||
|
|
||||||
isSecure := strings.HasPrefix(os.Getenv("BACKEND_URL"), HTTPS)
|
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.LogInfo("Copy this access token: " + accessToken)
|
||||||
helper.RespondWithJSON(w, http.StatusOK, map[string]string{
|
// helper.RespondWithJSON(w, http.StatusOK, map[string]string{
|
||||||
"message": "Authentication successful",
|
// "message": "Authentication successful",
|
||||||
"access_token": accessToken,
|
// "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 {
|
func validateState(w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user