jwt-go
jwt-go copied to clipboard
jwt-go generating invalid signature tokens
Hi!
I am trying to use jwt-go for authentication, but when I try to validate the token, I get: Error: signature is invalid
Sample token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTU4MjYzOTAsInJvbCI6InVzdWFyaW8iLCJ1c2VyIjoiZmFicyJ9.EtWzy5_b6qUyD_-uyD9XJll5R0XWW6ntISBEohwGmo4
It's invalid even checking in jwt.io
Code generating token:
token := jwt.New(jwt.SigningMethodHS256)
clamas := token.Claims.(jwt.MapClaims)
clamas["user"] = usuario.Username
clamas["rol"] = rol.Role
clamas["exp"] = time.Now().Add(time.Hour).Unix()
var err error
PToken, err = token.SignedString([]byte("el_secreto"))
if err != nil {
return err
}
Is there anything special I should use for HMAC secret in token.SingnedString ?
Thanks!!
You should retry your debugging. For me the sample token is valid and signature verified.
Ok, will check Thanks!
@fabstao Hey bro, did you find an answer on this? I am tired of this, more than a week and I still have this problem.
@fabstao Hey bro, did you find an answer on this? I am tired of this, more than a week and I still have this problem.
The problem is wrong use of jwt.io. Go ahead to jwt.io, delete the example, delete the string value "your 256 bits secret", write yours and after that paste your token. That's all
Now is working, thanks a lot!