use of com.auth0.jwt.Algorithm in project tutorials by jhkim105.
the class AuthenticationTokenUtil method generateToken.
public String generateToken(AuthUser authUser) {
Date now = new Date();
JWTCreator.Builder builder = JWT.create().withClaim(CLAIM_USER_ID, authUser.getUserId()).withClaim(CLAIM_USERNAME, authUser.getUsername()).withClaim(CLAIM_SCOPES, authUser.getScopes()).withIssuedAt(now);
if (this.expiry != 0)
builder.withExpiresAt(DateUtils.addSeconds(now, expiry));
String token = builder.sign(algorithm);
log.debug("token:{}", token);
return token;
}
use of com.auth0.jwt.Algorithm in project tutorials by jhkim105.
the class JwtAuthenticationTokenService method generateToken.
public String generateToken(AuthUser authUser, Date expireDate) {
Date now = new Date();
JWTCreator.Builder builder = JWT.create().withClaim("id", authUser.getId()).withClaim("username", authUser.getUsername()).withClaim("authority", authUser.getAuthority()).withIssuedAt(now);
if (expireDate != null)
builder.withExpiresAt(expireDate);
String token = builder.sign(algorithm);
log.debug("token:{}", token);
return token;
}
use of com.auth0.jwt.Algorithm in project study by bage2014.
the class JWTTest method main.
public static void main(String[] args) throws IllegalArgumentException, UnsupportedEncodingException {
// jjwt();
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
try {
Algorithm algorithm = Algorithm.HMAC256("your-256-bit-secret");
// Algorithm algorithm = Algorithm.HMAC256("your-256-bit-secret".getBytes("UTF-8"));
JWTVerifier verifier = JWT.require(algorithm).build();
DecodedJWT jwt = verifier.verify(token);
System.out.println(jwt);
} catch (JWTVerificationException exception) {
// Invalid signature/claims
exception.printStackTrace();
}
}
use of com.auth0.jwt.Algorithm in project su-sunday-cloud by illeagalName.
the class SecurityUtils method createToken.
/**
* 创建token
*
* @param payload 负载信息
* @param secret 加密串
* @param date 过期时间
* @return String
*/
public static String createToken(Map<String, String> payload, String secret, Date date) {
try {
// 秘钥及加密算法
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTCreator.Builder builder = JWT.create();
if (DataUtils.isNotEmpty(payload)) {
payload.forEach(builder::withClaim);
}
// 携带userId,userName信息,生成签名
return builder.withHeader(HEADER).withIssuedAt(new Date()).withExpiresAt(date).withSubject("vip").withIssuer("sunday").sign(algorithm);
} catch (Exception e) {
log.error("生成token异常", e);
return null;
}
}
use of com.auth0.jwt.Algorithm in project stream-java by GetStream.
the class Auth method buildFrontendToken.
public static Token buildFrontendToken(String secret, String userID, Date expiresAt) {
final Algorithm algorithm = Algorithm.HMAC256(secret);
JWTCreator.Builder builder = JWT.create().withClaim("user_id", userID);
if (expiresAt != null) {
builder = builder.withExpiresAt(expiresAt);
}
return new Token(builder.sign(algorithm));
}
Aggregations