use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.
the class JWTClientSecretCredentialsProvider method createRequestToken.
protected JsonWebToken createRequestToken(String clientId, String realmInfoUrl) {
// According to <a href="http://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication">OIDC's client authentication spec</a>,
// JWT claims is the same as one by private_key_jwt
JsonWebToken reqToken = new JsonWebToken();
reqToken.id(AdapterUtils.generateId());
reqToken.issuer(clientId);
reqToken.subject(clientId);
reqToken.audience(realmInfoUrl);
int now = Time.currentTime();
reqToken.issuedAt(now);
// the same as in KEYCLOAK-2986, JWTClientCredentialsProvider's timeout field
reqToken.expiration(now + 10);
reqToken.notBefore(now);
return reqToken;
}
use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.
the class JWTClientSecretCredentialsProvider method createSignedRequestToken.
public String createSignedRequestToken(String clientId, String realmInfoUrl, String algorithm) {
JsonWebToken jwt = createRequestToken(clientId, realmInfoUrl);
String signedRequestToken = null;
if (Algorithm.HS512.equals(algorithm)) {
signedRequestToken = new JWSBuilder().jsonContent(jwt).hmac512(clientSecret);
} else if (Algorithm.HS384.equals(algorithm)) {
signedRequestToken = new JWSBuilder().jsonContent(jwt).hmac384(clientSecret);
} else {
signedRequestToken = new JWSBuilder().jsonContent(jwt).hmac256(clientSecret);
}
return signedRequestToken;
}
use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.
the class JsonWebTokenTest method testArray.
@Test
public void testArray() throws IOException {
JsonWebToken jsonWebToken = new JsonWebToken();
jsonWebToken.audience("test", "test2");
assertTrue(JsonSerialization.writeValueAsPrettyString(jsonWebToken).contains("\"aud\" : [ \"test\", \"test2\" ]"));
}
use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.
the class JsonWebTokenTest method testAudSingle.
@Test
public void testAudSingle() throws IOException {
String single = "{ \"aud\": \"test\" }";
JsonWebToken s = JsonSerialization.readValue(single, JsonWebToken.class);
assertArrayEquals(new String[] { "test" }, s.getAudience());
}
use of org.keycloak.representations.JsonWebToken in project keycloak by keycloak.
the class JsonWebTokenTest method test.
@Test
public void test() throws IOException {
JsonWebToken jsonWebToken = new JsonWebToken();
jsonWebToken.audience("test");
assertTrue(JsonSerialization.writeValueAsPrettyString(jsonWebToken).contains("\"aud\" : \"test\""));
}
Aggregations