use of com.nimbusds.jose.Payload in project quickstart by wildfly.
the class JwtManager method createJwt.
public String createJwt(final String subject, final String[] roles) throws Exception {
JWSSigner signer = new RSASSASigner(privateKey);
JsonArrayBuilder rolesBuilder = Json.createArrayBuilder();
for (String role : roles) {
rolesBuilder.add(role);
}
JsonObjectBuilder claimsBuilder = Json.createObjectBuilder().add("sub", subject).add("iss", ISSUER).add("aud", AUDIENCE).add(CLAIM_ROLES, rolesBuilder.build()).add("exp", ((System.currentTimeMillis() / 1000) + TOKEN_VALIDITY));
JWSObject jwsObject = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.RS256).type(new JOSEObjectType("jwt")).build(), new Payload(claimsBuilder.build().toString()));
jwsObject.sign(signer);
return jwsObject.serialize();
}
Aggregations