title: How to extract and verify token sent from frontend
body: <p>I am using &quot;github.com/dgrijalva/jwt-go&quot;, and able to send a token to my frontend, and what I would like to know how I could retrieve the token sent from the frontend so that I can verify if the token that was sent is valid and if so the secured resource will be delivered.</p>
  <p>Here is the token sent from frontend JavaScript:</p>
  <pre><code>headers: {
         'Authorization':'Bearer' + localStorage.getItem('id_token')
       }
  </code></pre>
  <p>Here is the code to send token</p>
  <pre><code>    token := jwt.New(jwt.GetSigningMethod(&quot;HS256&quot;))
      claims := make(jwt.MapClaims)
      claims[&quot;userName&quot;] = loginRequest.UserName
      claims[&quot;exp&quot;] = time.Now().Add(time.Minute * 60).Unix()
      token.Claims = claims
      tokenString, err := token.SignedString([]byte(SecretKey))
      tokenByte, err := json.Marshal(data)
      w.WriteHeader(201)
      w.Write(tokenByte)
  </code></pre>
  <p>Here is the code to verify the token</p>
  <pre><code>    func VerifyToken(r *http.Request) bool {
  
      reqToken := r.Header.Get(&quot;Authorization&quot;)
      token, err := jwt.Parse(reqToken, func(t *jwt.Token) (interface{}, error) {
          return []byte(SecretKey), nil
      })
      if err == nil &amp;&amp; token.Valid {
          fmt.Println(&quot;valid token&quot;)
          return true
      } else {
          fmt.Println(&quot;invalid token&quot;)
          return false
      }
  
  }
  </code></pre>
  <p>Am getting <strong>nil</strong> token as a return, my guess is I have sent bearer and I think it might need parsing if so how?</p>