io.jsonwebtoken.ExpiredJwtException: JWT expired at 2021-11-11T14:48:14Z. Current time: 2021-11-11T14:48:50Z, a difference of 36843 milliseconds. Allowed clock skew: 0 milliseconds. at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:385) at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:481) at io.jsonwebtoken.impl.DefaultJwtParser.parseClaimsJws(DefaultJwtParser.java:541) at com.smart.util.JwtUtil.parseJwt(JwtUtil.java:63) at com.smart.util.JwtUtil.isTokenExpired(JwtUtil.java:93)
问题所在
根据报错堆栈信息找到了DefaultJwtParser类中,找到了问题的原因
boolean allowSkew = this.allowedClockSkewMillis > 0L; if (claims != null) { Date now = this.clock.now(); long nowTime = now.getTime(); Date exp = claims.getExpiration(); String nbfVal; SimpleDateFormat sdf; if (exp != null) { long maxTime = nowTime - this.allowedClockSkewMillis; Date max = allowSkew ? new Date(maxTime) : now; if (max.after(exp)) { sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); String expVal = sdf.format(exp); nbfVal = sdf.format(now); long differenceMillis = maxTime - exp.getTime(); String msg = "JWT expired at " + expVal + ". Current time: " + nbfVal + ", a difference of " + differenceMillis + " milliseconds. Allowed clock skew: " + this.allowedClockSkewMillis + " milliseconds."; thrownew ExpiredJwtException((Header)header, claims, msg); } }