use of org.keycloak.client.registration.ClientRegistration in project keycloak by keycloak.
the class FixedHostnameTest method assertInitialAccessTokenFromMasterRealm.
private void assertInitialAccessTokenFromMasterRealm(Keycloak testAdminClient, String realm, String expectedBaseUrl) throws JWSInputException, ClientRegistrationException {
ClientInitialAccessCreatePresentation rep = new ClientInitialAccessCreatePresentation();
rep.setCount(1);
rep.setExpiration(10000);
ClientInitialAccessPresentation initialAccess = testAdminClient.realm(realm).clientInitialAccess().create(rep);
JsonWebToken token = new JWSInput(initialAccess.getToken()).readJsonContent(JsonWebToken.class);
assertEquals(expectedBaseUrl + "/auth/realms/" + realm, token.getIssuer());
ClientRegistration clientReg = ClientRegistration.create().url(authServerUrl, realm).build();
clientReg.auth(Auth.token(initialAccess.getToken()));
ClientRepresentation client = new ClientRepresentation();
client.setEnabled(true);
ClientRepresentation response = clientReg.create(client);
String registrationAccessToken = response.getRegistrationAccessToken();
JsonWebToken registrationToken = new JWSInput(registrationAccessToken).readJsonContent(JsonWebToken.class);
assertEquals(expectedBaseUrl + "/auth/realms/" + realm, registrationToken.getIssuer());
}
use of org.keycloak.client.registration.ClientRegistration in project keycloak by keycloak.
the class FluentTestsHelper method createClient.
/**
* Creates a new client based on its representation.
*
* @param clientRepresentation Client data.
* @return <code>this</code>
*/
public FluentTestsHelper createClient(ClientRepresentation clientRepresentation) throws ClientRegistrationException, JsonProcessingException {
assert isInitialized;
ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
reg.auth(Auth.token(accessToken));
clientRepresentation = reg.create(clientRepresentation);
String registrationAccessCode = clientRepresentation.getRegistrationAccessToken();
reg.auth(Auth.token(registrationAccessCode));
createdClients.put(clientRepresentation.getClientId(), new ClientData(clientRepresentation, registrationAccessCode));
return this;
}
use of org.keycloak.client.registration.ClientRegistration in project keycloak by keycloak.
the class FluentTestsHelper method deleteClient.
/**
* Deletes a client previously created by this helper. This will throw an error if you try to delete an
* arbitrary client.
*
* @param clientId Client id to be deleted.
* @return <code>this</code>
* @throws ClientRegistrationException Thrown when client registration error occurs.
*/
public FluentTestsHelper deleteClient(String clientId) throws ClientRegistrationException {
assert isInitialized;
ClientData clientData = createdClients.get(clientId);
if (clientData == null) {
throw new ClientRegistrationException("This client wasn't created by this helper!");
}
ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
reg.auth(Auth.token(clientData.getRegistrationCode()));
reg.delete(clientId);
return this;
}
use of org.keycloak.client.registration.ClientRegistration in project keycloak by keycloak.
the class TestsHelper method createClient.
public static String createClient(ClientRepresentation clientRepresentation) {
ClientRegistration reg = ClientRegistration.create().url(keycloakBaseUrl, testRealm).build();
reg.auth(Auth.token(initialAccessCode));
try {
clientRepresentation = reg.create(clientRepresentation);
registrationAccessCode = clientRepresentation.getRegistrationAccessToken();
ObjectMapper mapper = new ObjectMapper();
reg.auth(Auth.token(registrationAccessCode));
clientConfiguration = mapper.writeValueAsString(reg.getAdapterConfig(clientRepresentation.getClientId()));
} catch (ClientRegistrationException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return clientConfiguration;
}
Aggregations