JSON Web Token library
- HS256
- HS384
- HS512
- RS256
- RS384
- RS512
- ES256
- ES384
- ES512
- PS256
- PS384
- PS512
package main
import (
"fmt"
"log"
"github.com/nasermirzaei89/jwt"
)
func main() {
token := jwt.New(jwt.HS256)
tokenStr, err := jwt.Sign(*token, []byte("secret_key"))
if err != nil {
log.Fatalln(err)
}
fmt.Println(tokenStr) // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.HUfJqC1q8JUPKD4jj8PZAYppSrQRL8tJHTljdcTfFCQ
}
package main
import (
"log"
"github.com/nasermirzaei89/jwt"
)
func main() {
tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.HUfJqC1q8JUPKD4jj8PZAYppSrQRL8tJHTljdcTfFCQ"
err := jwt.Verify(tokenStr, []byte("secret_key"))
if err != nil {
log.Fatalln(err)
}
}
package main
import (
"fmt"
"log"
"time"
"github.com/nasermirzaei89/jwt"
)
func main() {
token := jwt.New(jwt.HS256)
token.SetIssuer("https://yourdomain.tld")
token.SetExpirationTime(time.Now())
tokenStr, err := jwt.Sign(*token, []byte("secret_key"))
if err != nil {
log.Fatalln(err)
}
fmt.Println(tokenStr) // variable
}