February 2020
Intermediate to advanced
404 pages
8h 42m
English
The jwt-go package has a function called NewWithClaims that takes two arguments:
For example, it looks like the following code snippet:
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"username": "admin",
"iat":time.Now().Unix(),
})
jwt.SigningMethodHS256 is an encryption algorithm that is available within the package. The second argument is a map with claims such as private (here, username) and reserved (issued iat). Now, we can generate a tokenString using the SignedString function on a token, as follows:
tokenString, err := token.SignedString("my_secret_key")
This tokenString should then be sent back to the client as part of a successful ...
Read now
Unlock full access