use of org.keycloak.jose.jwk.JSONWebKeySet in project keycloak by keycloak.
the class OIDCJwksClientRegistrationTest method createClientWithManuallySetKid.
private OIDCClientRepresentation createClientWithManuallySetKid(String kid) throws Exception {
OIDCClientRepresentation clientRep = createRep();
clientRep.setGrantTypes(Collections.singletonList(OAuth2Constants.CLIENT_CREDENTIALS));
clientRep.setTokenEndpointAuthMethod(OIDCLoginProtocol.PRIVATE_KEY_JWT);
// Generate keys for client
TestOIDCEndpointsApplicationResource oidcClientEndpointsResource = testingClient.testApp().oidcClientEndpoints();
oidcClientEndpointsResource.generateKeys("RS256");
JSONWebKeySet keySet = oidcClientEndpointsResource.getJwks();
// Override kid with custom value
keySet.getKeys()[0].setKeyId(kid);
clientRep.setJwks(keySet);
return reg.oidc().create(clientRep);
}
use of org.keycloak.jose.jwk.JSONWebKeySet in project keycloak by keycloak.
the class ClientAuthSignedJWTTest method setupJwks.
private KeyPair setupJwks(String algorithm, ClientRepresentation clientRepresentation, ClientResource clientResource) throws Exception {
// generate and register client keypair
TestOIDCEndpointsApplicationResource oidcClientEndpointsResource = testingClient.testApp().oidcClientEndpoints();
oidcClientEndpointsResource.generateKeys(algorithm);
Map<String, String> generatedKeys = oidcClientEndpointsResource.getKeysAsBase64();
KeyPair keyPair = getKeyPairFromGeneratedBase64(generatedKeys, algorithm);
// use and set JWKS
OIDCAdvancedConfigWrapper.fromClientRepresentation(clientRepresentation).setUseJwksString(true);
JSONWebKeySet keySet = oidcClientEndpointsResource.getJwks();
OIDCAdvancedConfigWrapper.fromClientRepresentation(clientRepresentation).setJwksString(JsonSerialization.writeValueAsString(keySet));
clientResource.update(clientRepresentation);
// set time offset, so that new keys are downloaded
setTimeOffset(20);
return keyPair;
}
use of org.keycloak.jose.jwk.JSONWebKeySet in project keycloak by keycloak.
the class OAuthClient method getRealmPublicKey.
private KeyWrapper getRealmPublicKey(String realm, String algoritm, String kid) {
boolean loadedKeysFromServer = false;
JSONWebKeySet jsonWebKeySet = publicKeys.get(realm);
if (jsonWebKeySet == null) {
jsonWebKeySet = getRealmKeys(realm);
publicKeys.put(realm, jsonWebKeySet);
loadedKeysFromServer = true;
}
KeyWrapper key = findKey(jsonWebKeySet, algoritm, kid);
if (key == null && !loadedKeysFromServer) {
jsonWebKeySet = getRealmKeys(realm);
publicKeys.put(realm, jsonWebKeySet);
key = findKey(jsonWebKeySet, algoritm, kid);
}
if (key == null) {
throw new RuntimeException("Public key for realm:" + realm + ", algorithm: " + algoritm + " not found");
}
return key;
}
Aggregations