title: Find out current user name in golang server that uses Auth0
body: <p>I am using <code>auth0</code> and <code>golang</code> for a rest service that is similar implemented as shown <a href="https://github.com/auth0-blog/auth0-golang-jwt/blob/master/main.go" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I wonder how I can find out the name of the user that is currently triggering a certain API call - for instance if someone requests <code>http://localhost:3000/products</code> - the go handler in this case looks like this:</p>
  
  <pre><code>var ProductsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      payload, _ := json.Marshal(products)
  
      w.Header().Set("Content-Type", "application/json")
      w.Write([]byte(payload))
  })
  </code></pre>
  
  <p>Does the request <code>r</code> contain more information about the current user?</p>
  
  <p>Or do I need to find out the current user in the middleware authentication:</p>
  
  <pre><code>func authMiddleware(next http.Handler) http.Handler {
      return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
          secret := []byte("{YOUR-AUTH0-API-SECRET}")
          secretProvider := auth0.NewKeyProvider(secret)
          audience := "{YOUR-AUTH0-API-AUDIENCE}"
  
          configuration := auth0.NewConfiguration(secretProvider, audience, "https://{YOUR-AUTH0-DOMAIN}.auth0.com/", jose.HS256)
          validator := auth0.NewValidator(configuration)
  
          token, err := validator.ValidateRequest(r)
  
          if err != nil {
              fmt.Println(err)
              fmt.Println("Token is not valid:", token)
              w.WriteHeader(http.StatusUnauthorized)
              w.Write([]byte("Unauthorized"))
          } else {
              next.ServeHTTP(w, r)
          }
      })
  }
  </code></pre>
  
  <p>Does the <code>token</code> contain more information about the user?</p>
  
  <p>I am a bit lost here. <code>auth0</code> works perfectly to ensure that only registered persons can use the REST-API, but I want to deliver user specific information. So it depends on the current user what a REST call is handing back. Initially, I was thinking that auth0 would take care of this. Is there a simple way to achieve this? </p>