Passing parameters between the login and the callback functions
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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