I am trying to generate a JWT token but having trouble when it comes to converting everything to a byte array.
func GenerateToken(uid, cid int64) string{
header := `{"alg": "HS256","typ": "JWT"}`
header = base64.URLEncoding.EncodeToString([]byte(header))
var b structs.JwtBody
b.UID = uid
b.CID = cid
body, _ := json.Marshal(b)
key := []byte(secret)
h := hmac.New(sha256.New, key)
h.Write([]byte(header + "." + body))
signature := base64.URLEncoding.EncodeToString(h.Sum(nil))
jwt := header + "." + body + "." + signature
return jwt
}
I am getting an error with this line because the types do not match up.
h.Write([]byte(header + "." + body))
How do I fix this?