Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not find a matching session for this request only on android device #582

Open
noahfraiture opened this issue Nov 18, 2024 · 0 comments

Comments

@noahfraiture
Copy link

Hello,

I made a website with go for the backend with a simple login system with google :

func GoogleLogin(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	q.Add("provider", "google")
	r.URL.RawQuery = q.Encode()

	gothic.BeginAuthHandler(w, r)
}

func GoogleCallback(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	q.Add("provider", "google")
	r.URL.RawQuery = q.Encode()

	user, err := gothic.CompleteUserAuth(w, r)
	if err != nil {
		fmt.Println(err)
		http.Error(w, "Error during authentication", http.StatusInternalServerError)
		return
	}
	dbPool, err := db.GetPool()
	if err != nil {
		http.Error(w, "Can't get db", http.StatusInternalServerError)
		return
	}
	err = auth.SaveUser(dbPool, user, w, r)
	if err != nil {
		fmt.Println(err)
		http.Error(w, "Error during saving user", http.StatusInternalServerError)
		return
	}
	http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}

And the configuration is the following :

func Init() {
	// Load environment variables
	clientID := os.Getenv("GOOGLE_ID")
	clientSecret := os.Getenv("GOOGLE_SECRET")
	clientCallbackURL := os.Getenv("GOOGLE_CALLBACK_URL")
	sessionSecret := os.Getenv("SESSION_SECRET")

	// Check that all necessary variables are set
	if clientID == "" || clientSecret == "" || clientCallbackURL == "" || sessionSecret == "" {
		log.Fatal("Environment variables (GOOGLE_ID, GOOGLE_SECRET, GOOGLE_CALLBACK_URL, SESSION_SECRET) are required")
	}

	store = sessions.NewCookieStore([]byte(sessionSecret))

	// Set up Google provider for Goth
	goth.UseProviders(google.New(clientID, clientSecret, clientCallbackURL))

	// Configure the session store with the session secret
	store := sessions.NewCookieStore([]byte(sessionSecret))
	gothic.Store = store
}

The problem is that the login phase works perfectly on my computer (even with different IP, clean cache and different browser and even different laptop), but on my android device, I get the error could not find a matching session for this request that occurs on gothic.CompleteUserAuth. I'm sure that the URI are well configured in Google redirect URI and again it works well on my laptop.
How can there be a difference between a computer and a android devices ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant