InvalidClaimException: The Token can‘t be used before

InvalidClaimException: The Token can‘t be used before,第1张

InvalidClaimException: The Token can‘t be used before 项目场景:

服务分布式部署token验证出错


问题描述:
InvalidClaimException: The Token can't be used before ......
原因分析:

多台服务器情况下,时钟同步存在误差导致token时间超前。

获取token的服务器比使用token的服务器时钟快,请求分发到时间慢的服务器上导致时间还没到token的开始时间。


解决方案:

设置允许误差时间:

Algorithm algorithm = Algorithm.HMAC256(SECRET_KEY);
JWTVerifier verifier = JWT.require(algorithm).acceptLeeway(2).build();
verifier.verify(token);

源码:

JWTVerifier.java
 private void assertDateIsPast(Date date, long leeway, Date today) {
        today.setTime(today.getTime() + leeway * 1000L);
        if (date != null && today.before(date)) {
            throw new InvalidClaimException(String.format("The Token can't be used before %s.", date));
        }
    }


问题参考:issues

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5685392.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存