"Missing required parameter: code" on github login

For some reason whenever I’m logging in with Google account everything works, but with GitHub there is “Missing required parameter: code” error

I’m using code similar to Golang sample auth0 app.


domain := os.Getenv("AUTH0_DOMAIN")
	conf := &oauth2.Config{
		ClientID:     os.Getenv("AUTH0_CLIENT_ID"),
		ClientSecret: os.Getenv("AUTH0_CLIENT_SECRET"),
		RedirectURL:  os.Getenv("AUTH0_CALLBACK_URL"),
		Scopes:       ]string{"openid", "profile"},
		Endpoint: oauth2.Endpoint{
			AuthURL:  "https://" + domain + "/authorize",
			TokenURL: "https://" + domain + "/oauth/token",
		},
	}

	code := c.URLParamTrim("code")

	token, err := conf.Exchange(context.TODO(), code)
	if err != nil {
		log.WithError(err).WithField("code", code).Error("Token not received")
      }

Maybe there are some tips how to find the problem?

The result of the initial authorization step (when doing an authorization code grant) can either be an authorization code or an error response; given that the error you posted is about an authorization code not being present then the most likely explanation is that the response you received from the authorization endpoint was an error response.

In the event of the redirect URL being called with an error response there will be an error parameter in the query component that hints at the source of the issue. In addition it’s also likely that a error_description will also be available. I’m not overly familiar with Go, but the priority for troubleshooting the issue should be to first check if you indeed got an authorization error response and if so obtain the values of the error and error_description. When doing this in Chrome you can quickly confirm and obtain this information by inspecting the HTTP requests/responses in the network tab.

You are right. I actually got error_description, which was something like cannot get proper "username" of undefined.

Don’t really know what to do with that error, too.