use of org.gluu.oxauth.model.jwt.JwtClaims in project oxAuth by GluuFederation.
the class UserInfoRestWebServiceImpl method createJwtClaims.
private JwtClaims createJwtClaims(User user, AuthorizationGrant authorizationGrant, Collection<String> scopes) throws Exception {
String claimsString = getJSonResponse(user, authorizationGrant, scopes);
JwtClaims claims = new JwtClaims(new JSONObject(claimsString));
claims.setIssuer(appConfiguration.getIssuer());
Audience.setAudience(claims, authorizationGrant.getClient());
return claims;
}
use of org.gluu.oxauth.model.jwt.JwtClaims in project oxAuth by GluuFederation.
the class JwkRestWebServiceEmbeddedTest method setClaimTestIntList.
@Test
public void setClaimTestIntList() {
try {
JwtClaims claims = new JwtClaims();
claims.setClaim("test_claim", Arrays.asList(123, 456, 789));
assertEquals("{\"test_claim\":[123,456,789]}", claims.toJsonObject().toString());
} catch (Exception ex) {
fail(ex.getMessage());
}
}
use of org.gluu.oxauth.model.jwt.JwtClaims in project oxAuth by GluuFederation.
the class JwkRestWebServiceEmbeddedTest method setClaimTestJsonObj.
@Test
public void setClaimTestJsonObj() {
try {
String stringJson = StringUtil.fromBytes(Base64Util.base64urldecode("eyJzYWx0IjoibWFjbmgiLCJwcm92aWRlciI6ImlkcDEifQ=="));
JSONObject jobj = new JSONObject(stringJson);
JwtClaims claims = new JwtClaims();
claims.setClaim("test_claim", jobj);
assertEquals(jobj, claims.toJsonObject().get("test_claim"));
} catch (Exception ex) {
fail(ex.getMessage());
}
}
use of org.gluu.oxauth.model.jwt.JwtClaims in project oxAuth by GluuFederation.
the class JwtState method getEncodedJwt.
public String getEncodedJwt(JSONObject jwks) throws Exception {
String encodedJwt = null;
if (keyEncryptionAlgorithm != null && blockEncryptionAlgorithm != null) {
JweEncrypterImpl jweEncrypter;
if (cryptoProvider != null && jwks != null) {
PublicKey publicKey = cryptoProvider.getPublicKey(keyId, jwks, null);
jweEncrypter = new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, publicKey);
} else {
jweEncrypter = new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, sharedKey.getBytes(Util.UTF8_STRING_ENCODING));
}
String header = ClientUtil.toPrettyJson(headerToJSONObject());
String encodedHeader = Base64Util.base64urlencode(header.getBytes(Util.UTF8_STRING_ENCODING));
String claims = ClientUtil.toPrettyJson(payloadToJSONObject());
String encodedClaims = Base64Util.base64urlencode(claims.getBytes(Util.UTF8_STRING_ENCODING));
Jwe jwe = new Jwe();
jwe.setHeader(new JwtHeader(encodedHeader));
jwe.setClaims(new JwtClaims(encodedClaims));
jweEncrypter.encrypt(jwe);
encodedJwt = jwe.toString();
} else {
if (cryptoProvider == null) {
throw new Exception("The Crypto Provider cannot be null.");
}
JSONObject headerJsonObject = headerToJSONObject();
JSONObject payloadJsonObject = payloadToJSONObject();
String headerString = ClientUtil.toPrettyJson(headerJsonObject);
String payloadString = ClientUtil.toPrettyJson(payloadJsonObject);
String encodedHeader = Base64Util.base64urlencode(headerString.getBytes(Util.UTF8_STRING_ENCODING));
String encodedPayload = Base64Util.base64urlencode(payloadString.getBytes(Util.UTF8_STRING_ENCODING));
String signingInput = encodedHeader + "." + encodedPayload;
String encodedSignature = cryptoProvider.sign(signingInput, keyId, sharedKey, signatureAlgorithm);
encodedJwt = encodedHeader + "." + encodedPayload + "." + encodedSignature;
}
return encodedJwt;
}
Aggregations