public static String createToken(final String applyUser, ApiServiceToken apiServiceToken, Long duration) {
        final String role = "developer";
        final Instant now = Instant.now();
        final Date expiryDate = Date.from(now.plus(Duration.ofDays(duration)));
        Map<String, Object> tokenDetailMap = new HashMap<String, Object>();
        tokenDetailMap.put("tokenDetail", apiServiceToken);
        return Jwts.builder()
                .setSubject(applyUser)
                .claim(CLAIM_ROLE, role)
                .setClaims(tokenDetailMap)
                .setExpiration(expiryDate)
                .setIssuedAt(Date.from(now))
                .signWith(SIGNATURE_ALGORITHM, generalKey())
                .compact();
    }
Builds a JWT with the given subject and role and returns it as a JWS signed compact String.
dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/token/JwtManager.java