I am trying to verify JWT in Next.js app with many different approach ( using crypto or jsonwebtoken libraries ) but every time I get error.
This is how JWT is signed :
public String generateToken(UserDetails userDetails) {
return generateToken(new HashMap<>(), userDetails);
}
public String generateToken(
Map<String, Object> extraClaims,
UserDetails userDetails
) {
return Jwts
.builder()
.setClaims(extraClaims)
.setSubject(userDetails.getUsername())
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 24))
.signWith(getSignInKey(), SignatureAlgorithm.HS256)
.compact();
}
private Key getSignInKey() {
byte[] keyBytes = Decoders.BASE64.decode(SECRET_KEY);
return Keys.hmacShaKeyFor(keyBytes);
}
This use SpringSecurity 6. In version 5, it was possible to call signWith method secret_key that is typeof String, but in version 6 secret_key must be typeof Key.
So I don't know what should I do now for JWT verification, is there anyone who face this problem?