Auto0生成JWT令牌


private static Integer expiredTimeIn = 86400000;

private static String getToken(Long uid) {

        // 选择加密算法
        Algorithm algorithm = Algorithm.HMAC256(JwtToken.jwtKey);
        // 设置过期时间
        Map map = JwtToken.calculateExpiredIssues();

        return JWT.create()
                .withClaim("uid", uid)
                .withExpiresAt(map.get("expiredTime"))
                .withIssuedAt(map.get("now"))
                .sign(algorithm);
}


/**
 * 计算签发时间和过期时间
 * @return
 */
private static Map calculateExpiredIssues() {
    Map map = new HashMap<>();
    Calendar calendar = Calendar.getInstance();
    Date now = calendar.getTime();
    calendar.add(Calendar.SECOND, JwtToken.expiredTimeIn);
    map.put("now", now);
    map.put("expiredTime", calendar.getTime());
    return map;
}

你可能感兴趣的:(Auto0生成JWT令牌)