title: Can't solve "token contains an invalid number of segments"
body: <p>I am using for the generation of tokens an identity provider and the generated token is valid (tested on <a href="https://jwt.io/" rel="nofollow noreferrer">https://jwt.io/</a>). My main issue is the error <em>&quot;token contains an invalid number of segments&quot;</em>, when I'm extracting the token from the authorization header. I have tipped the token into a variable and by doing so, it actually worked.I got the confirmation, that the token is valid. But in order for the application to work properly, I need to <strong>extract the token from the authentification header</strong>.</p>
  <pre><code>import (
      &quot;fmt&quot;
      &quot;github.com/golang-jwt/jwt&quot;
      &quot;net/http&quot;
  )
  var ReqToken string
  
  func verifyToken(w http.ResponseWriter, r *http.Request) bool {
      SecretKey := &quot;SECRETKEY&quot;
      ReqToken = r.Header.Get(&quot;Authorization&quot;)
      key, er := jwt.ParseRSAPublicKeyFromPEM([]byte(SecretKey))
      if er != nil {
          fmt.Println(er)
  
          w.WriteHeader(http.StatusUnauthorized)
          return false
      }
  
      token, err := jwt.Parse(ReqToken, func(token *jwt.Token) (interface{}, error) {
          
          if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
              return nil, fmt.Errorf(&quot;Unexpected signing method: %v&quot;, token.Header[&quot;alg&quot;])
          }
          return key, nil
      })
  
      if err != nil {
          fmt.Println(err)
          w.WriteHeader(http.StatusUnauthorized)
          return false
      }
      return true
  }
  </code></pre>
  <p>I am receiving the error after I send a request to the backend. How should I approach this error?</p>