我想exp
从 JSON Web 令牌 (JWT) 解析到期日期 (),而不进行验证。我尝试了以下脚本(试图遵循How to parse unix timestamp to time.Time):
package main
import (
"fmt"
"log"
"strconv"
"time"
jwt "github.com/dgrijalva/jwt-go"
)
func main() {
tokenString := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{})
if err != nil {
log.Fatal(err)
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
fmt.Println(claims["exp"])
i, err := strconv.ParseInt(claims["exp"].(string), 10, 64)
if err != nil {
log.Fatal(err)
}
tm := time.Unix(i, 0)
fmt.Println(tm)
}
}
但是,我收到此错误:
> go run main.go
<nil>
panic: interface conversion: interface {} is nil, not string
goroutine 1 [running]:
main.main()
/Users/kurt/go/src/github.com/khpeek/mygoproject/jwt_validation/main.go:23 +0x34a
exit status 2
有没有办法exp
从jwt
图书馆里得到一个字符串?我怎样才能让这给我iat
JWT 的到期日期(或 )?