lundi 13 juillet 2020

Testing validity time of the token

I want to test my token's validity time and when i wrote the code and restart the server the secret key change. For this reason my tests always fail. How can i fix it?

Here are my isExpired and its aux-method:

final Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256); //This key always
// change if i restart server
.
.
.
public boolean isExpired(String token) {
    Claims claims = getClaims(token);
    return claims.getExpiration().after(new Date(System.currentTimeMillis()));
}

private Claims getClaims(String token) {
    return Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
}

Aucun commentaire:

Enregistrer un commentaire