use of com.auth0.jwt.Algorithm in project code by lastwhispers.
the class UserController method login.
/**
* http://localhost:8080/user/login?username=admin&password=123456
*
* @param username
* @param password
* @return
*/
@GetMapping("/login")
public String login(@RequestParam String username, @RequestParam String password) {
Algorithm algorithm = Algorithm.HMAC256(JWT_KEY);
String token = JWT.create().withClaim(CURRENT_USER, username).withClaim(UID, 1).withExpiresAt(new Date(System.currentTimeMillis() + 3600000)).sign(algorithm);
return token;
}
use of com.auth0.jwt.Algorithm in project jobs by damingerdai.
the class JWTUtil method sign.
/**
* 生成签名,5min后过期
* @param username 用户名
* @param secret 用户的密码
* @return 加密的token
*/
public static String sign(String username, String secret) {
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
Algorithm algorithm = Algorithm.HMAC256(secret);
// 附带username信息
return JWT.create().withClaim("username", username).withExpiresAt(date).sign(algorithm);
}
use of com.auth0.jwt.Algorithm in project jobs by damingerdai.
the class JwtTool method verifyToken.
public static boolean verifyToken(String token, String secret) {
try {
Algorithm algorithm = Algorithm.HMAC256(secret);
var verifier = JWT.require(algorithm).build();
var jwt = verifier.verify(token);
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
use of com.auth0.jwt.Algorithm in project sports_hub_portal by Anastasiia-Rokytska.
the class JwtTokenService method verifyToken.
public String verifyToken(String token) {
JWTVerifier verifier = JWT.require(algorithm).build();
DecodedJWT decodedJWT = verifier.verify(token);
return decodedJWT.getSubject();
}
use of com.auth0.jwt.Algorithm in project bitrxc-server by bitrxc.
the class TokenManager method createTokenForAdmin.
// 管理员端token生成
public String createTokenForAdmin(String phone) {
Date expirationTime = new Date(System.currentTimeMillis() + this.tokenExpiration);
// 私钥及加密算法
Algorithm algorithm = Algorithm.HMAC256(tokenSignKey);
// 设置头信息
Map<String, Object> header = new HashMap<>();
header.put("typ", "JWT");
header.put("alg", "HS256");
return JWT.create().withHeader(header).withExpiresAt(expirationTime).withClaim("phone", phone).sign(algorithm);
}
Aggregations