I need to use JWT in mi API, and the IDE tells me that the .signWith() method is deprecated. So far I use the @Deprecated annotation, but I think this is not so good practice.
This is my example code:
@Deprecated
public String generateToken(UserDetails userDetails) {
return Jwts.builder().setSubject(userDetails.getUsername()).setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() 1000 * 60 * 60 * 10))
.signWith(SignatureAlgorithm.HS256, KEY).compact();
}
CodePudding user response:
As per the source code you need to flip the variables so that Key comes first:
@deprecated since 0.10.0: use {@link #signWith(Key, SignatureAlgorithm)} instead. This method will be removed in the 1.0 release.
@Deprecated JwtBuilder signWith(SignatureAlgorithm alg, Key key) throws InvalidKeyException;