java - 当前 token 的生命周期

标签 java oauth-2.0 jwt

我有一个具有以下有效负载的 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 的生命周期。

有人可以建议这样做的最佳方法吗?

最佳答案

  1. 获取当前纪元时间(此处 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/

相关文章:

jwt - 如何在 Thinktecture Identity Server 中加密 JWT token ?

spring-boot - 当 Spring Boot 应用程序使用 nginx Controller 部署到 kubernetes 集群时,JWT 身份验证不起作用

使用 Auth API 的 SPA 的 Azure B2C 隐式流为 openid 范围提供无效 token

spring-security - Spring security oauth 2 简单示例

php - 如何在 PHP 中获取 OAuth 2.0 token ?

php - 刷新 token AWS Cognito 用户池

java - 可以使用 lambda 表达作为 Function 的枚举的实现吗?

java - 如何在其他类中传递类的值?

java - 3D "free"相机的三角学

java - 不同语言的相同算法的不同输出