我有一个具有以下有效负载的 JWT:
{
"id": "394a71988caa6cc30601e43f5b6569d52cd7f6df",
"jti": "394a71988caa6cc30601e43f5b6569d52cd7f6df",
"iss": "issuer_id",
"aud": "client_id",
"sub": "user_id",
"exp": 1483711650,
"iat": 1483708050,
"token_type": "bearer",
"scope": "onescope twoscope"
}
iat:在纪元时间发布
exp:在纪元时间内到期
我目前想检查 token 的生命周期。
有人可以建议这样做的最佳方法吗?
最佳答案
- 获取当前纪元时间(此处 Instant 来自 java.time.Instant 包)
long currentTimeEpocSec = Instant.now().getEpochSecond()
然后用当前时间减去过期时间,得到以秒为单位的持续时间。
long duration = expiresAt - currentTimeEpocSec;
以秒为单位
long durationInMinutes = duration / 60;
关于java - 当前 token 的生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59158307/