- 
                Notifications
    You must be signed in to change notification settings 
- Fork 420
Closed
Description
I need to set the valid time of token to 100ms, but I got "Token is expired" err. is there any way to make it?
func TestJWTRsaMS(t *testing.T) {
privateKeyByte, _ := ioutil.ReadFile("private.key")
privateKey, _ := jwt.ParseRSAPrivateKeyFromPEM(privateKeyByte)
jwt.TimePrecision = time.Millisecond
publicKeyByte, _ := ioutil.ReadFile("private.key.pub")
publicKey, _ := jwt.ParseRSAPublicKeyFromPEM(publicKeyByte)
token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
	"exp": time.Now().Add(time.Millisecond*time.Duration(100)).UnixNano() / 1e6,
	"iat": time.Now().UnixNano() / 1e6,
	"subject": map[string]string{
		"a": "123",
		"b": "321",
	},
})
tokenStr, err := token.SignedString(privateKey)
if err != nil {
	t.Logf("token.SignedString err:%s", err)
	return
}
_, err = jwt.Parse(tokenStr, func(token *jwt.Token) (interface{}, error) {
	return publicKey, nil
})
if err != nil {
	t.Logf("%s", err)
}
}
Metadata
Metadata
Assignees
Labels
No labels