title: Golang package jwt-go with rsa key. How to put the public key and how to get it from the token?
body: <p>I'm trying to generate a token with a rsa key using the jwt-go package in golang.</p>
  
  <p><a href="https://sendgrid.com/blog/tokens-tokens-intro-json-web-tokens-jwt-go/" rel="nofollow noreferrer">Here</a> there is a blog explaining how to do it but that code will always be validating all tokens because is using the public key stored in the server and is not obtaining it from the token. How do you put the complete public key in the token? I was trying this:</p>
  
  <pre><code>var secretKey, _ = rsa.GenerateKey(rand.Reader, 1024)
  token := jwt.New(jwt.SigningMethodRS256)
  token.Claims["username"] = "victorsamuelmd"
  token.Claims["N"] = secretKey.PublicKey.N
  token.Claims["E"] = secretKey.PublicKey.E
  
  tokenString, err := token.SignedString(secretKey)
  
  nt, err := jwt.Parse(tokenString, func(t *jwt.Token) (interface{}, error) {
      // here I need to recover the public key from the token
      // but N is a big.Int and the token stores N as int64
  })
  </code></pre>
  
  <p>Sorry about my english. Thanks.</p>