markbates / markbates/goth

Passing parameters between the login and the callback functions

Open
#507 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
6.6k
Forks
631
PR merge metrics
No merged PRs in 30d

Description

I'm in a weird situation where when I call the auth_callback, I need to know how the auth flow was initiated:

func Login(c *gin.Context) {
	var loginUrl LoginUrl
	if err := c.BindQuery(&loginUrl); err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	var w http.ResponseWriter = c.Writer
	var req *http.Request = c.Request

	logger.Debug("Starting auth flow")
	url, err := gothic.GetAuthURL(c.Writer, c.Request)

	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
	}

	err = gothic.StoreInSession("is_web", strconv.FormatBool(loginUrl.IsWeb), req, w)
	c.Redirect(http.StatusFound, url)
}
func AuthCallback(c *gin.Context) {
	user, err := gothic.CompleteUserAuth(c.Writer, c.Request)
	fmt.Println("user: ", user)
	is_web, _ := gothic.GetFromSession("is_web", c.Request)
	fmt.Println("it's web or not", is_web)
}

Basically when I start the flow, I call mysite.com/auth/provider_name?is_web=true. I'm parsing the is_web parameter in the Login function, and I'm then trying to store it in the gothic session.

Then when AuthCallback is triggered, I'm trying to get is_web back, but the call to gothic.CompleteUserAuth raises an error: you must select a provider. I believe at this point the content of the session is overwritten? Does the call to StoreInSession wipe out the relevant info?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Login and AuthCallback entry points and trace gothic.GetAuthURL, StoreInSession, CompleteUserAuth, and GetFromSession through the shown request sequence. Reproduce the provider callback error and inspect how session state is preserved between requests. Done means determining whether storing is_web affects provider selection and documenting or correcting the resulting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.