我正在 Jersey 编写 API 代码并生成令牌,我正在使用 jwt 罐子。
我在类路径中有以下罐子。
生成token的代码如下-
public class JWTTokenProvider {
//TODO set it in properties file
private String jwtSecret = "ad165b11320bc91501ab08613cc3a48a62a6caca4d5c8b14ca82cc313b3b96cd";//https://emn178.github.io/online-tools/sha256.html
private String jwtExpirationDate;
public String generateToken(String username) {
Date currentDate = new Date();
//TODO set jwtExpirationDate in properties file
Date expiryDate = new Date(currentDate.getTime() + 1000*60*60*10);
String token = Jwts.builder().setSubject(username).setIssuedAt(new Date()).setExpiration(expiryDate)
.signWith(key()).compact();
return token;
}
private Key key() {
return Keys.hmacShaKeyFor(Decoders.BASE64.decode(jwtSecret));
}
}
紧凑方法失败。
我调试并注意到以下内容,Serliazer 类来自不同的包而不是 JWT
我在这里错过了什么?任何帮助都会得到帮助。