title: oauth2 cannot fetch token: bad request
body: <p>I write a handler so that when accessing the route <code>/auth/google/callback</code>, I try to login with Google account through OAuth2. The handler is implemented like this:</p>
  
  <pre><code>package route
  
  import (
      "net/http"
      "golang.org/x/oauth2"
      "golang.org/x/oauth2/google"
      "fmt"
  )
  
  func GoogleOAuthHandler(w http.ResponseWriter, r *http.Request) {
      conf:=&amp;oauth2.Config{
          ClientID:"myclientid",
          ClientSecret:"myclientsecret",
          RedirectURL:"http://localhost:3000",
          Scopes:[]string{
              "https://www.googleapis.com/auth/userinfo.profile",
              "https://www.googleapis.com/auth/userinfo.email",
          },
          Endpoint:google.Endpoint,
      }
  
      code := r.URL.Query().Get("code")
  
      token, err := conf.Exchange(oauth2.NoContext, code)
      if err != nil {
          http.Error(w, err.Error(), http.StatusInternalServerError)
          return
      }
  
      fmt.Println(token)
  
      http.Redirect(w, r, "/", http.StatusMovedPermanently)
  }
  </code></pre>
  
  <p>In <code>func main()</code>, <code>http.HandleFunc("/auth/google/callback",route.GoogleOAuthHandler)</code> is setup</p>
  
  <p>When I access that path, it throws an error like this on browser:</p>
  
  <pre><code>oauth2: cannot fetch token: 400 Bad Request
  Response: {
    "error" : "invalid_request",
    "error_description" : "Missing required parameter: code"
  }
  </code></pre>
  
  <p>Did I miss something? Please instruct me to make a proper access to OAuth2 and get token and information from Google account</p>