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

Pickup provider name from go 1.22 mux #552

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pinpox
Copy link

@pinpox pinpox commented Apr 24, 2024

Using the new mux addet to go 1.22 natively, the provider name is not picked up. It mostly replaces gorilla/pat in many places, e.g. path parameters.

There is the alternative of working around this like this:

	mux.HandleFunc("GET /auth/{provider}", func(res http.ResponseWriter, req *http.Request) {
		// try to get the user without re-authenticating

		// goth doesn't pick up the provider using the go 1.22 new routers, so
		// we work around by setting it in the context.
		req = req.WithContext(context.WithValue(req.Context(), "provider", req.PathValue("provider")))

		if gothUser, err := gothic.CompleteUserAuth(res, req); err == nil {
			err = templates.ExecuteTemplate(res, "user.html", gothUser)
			if err != nil {
				panic(err)
			}
		} else {

			gothic.BeginAuthHandler(res, req)
		}
	})

By merging this PR it would no longer be necessary to set the provider explicitely in the context of the request.

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

Successfully merging this pull request may close these issues.

None yet

1 participant