title: JWT token expiration check
body: <p>I've a following utility class but whenever I check for an expired Token via verify method, it's not throwing the <code>JWtVerificationException</code>.</p>
  
  <pre><code>public class Token {
  
      private static String SECRET = "c3bff416-993f-4760-9275-132b00256944";
  
      public static String get(String name, String value) throws UnsupportedEncodingException {
          return JWT.create()
                  .withIssuer("auth0")
                  .withClaim(name, value)
                  .withClaim("random", String.valueOf(UUID.randomUUID()))
                  .withExpiresAt(new Date(System.currentTimeMillis() + (4 * 60 * 60 * 1000)))
                  .sign(Algorithm.HMAC256(Token.SECRET));
      }
  
      public static DecodedJWT verify(String token) throws JWTVerificationException, UnsupportedEncodingException {
          JWTVerifier verifier = JWT.require(Algorithm.HMAC256(Token.SECRET))
                  .withIssuer("auth0")
                  .acceptExpiresAt(4)
                  .build();
  
          return verifier.verify(token);
      }
  
  }
  </code></pre>
  
  <p>As per the website <a href="https://github.com/auth0/java-jwt" rel="nofollow noreferrer">https://github.com/auth0/java-jwt</a> </p>
  
  <blockquote>
    <blockquote>
      <p>When verifying a token the time validation occurs automatically, resulting in a <code>JWTVerificationException</code> being throw when the values are invalid. </p>
    </blockquote>
  </blockquote>
  
  <p><strong>Edit:</strong> </p>
  
  <p>A case when client renewing token every 5 minutes, will following work or should I add few extra seconds to accommodate any network lag?</p>
  
  <p>creates</p>
  
  <pre><code>.withExpiresAt(new Date(System.currentTimeMillis() + (5 * 60 * 1000))) // 5 minutes
  </code></pre>
  
  <p>verify</p>
  
  <pre><code>.acceptExpiresAt(5 * 60) // accept expiry of 5 minutes
  </code></pre>