jwt-go
jwt-go copied to clipboard
looking for example of
I see this in the docs:
// Create a new token object, specifying signing method and the claims
// you would like it to contain.
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"foo": "bar",
"nbf": time.Date(2015, 10, 10, 12, 0, 0, 0, time.UTC).Unix(),
})
// Sign and get the complete encoded token as a string using the secret
tokenString, err := token.SignedString(hmacSampleSecret)
fmt.Println(tokenString, err)
I see no reference to hmacSampleSecret
I have no idea how to generate that? can it be documented? ty
the docs for this are: https://godoc.org/github.com/dgrijalva/jwt-go#example-New--Hmac
hmacSampleSecret is the secret you need to set. example: hmacSampleSecret := []byte("the secret key for you") or var hmacSampleSecret []byte if keyData, e := ioutil.ReadFile("test/hmacTestKeyFile"); e == nil { hmacSampleSecret = keyData }
For HS256 the secret is a bytes array of your choosing. As @ygj6 says, just pick one and use it as input to SignedString