Last active
August 8, 2017 03:42
-
-
Save gastaldi/c8a3967a5d309ae59a77e07fb11db462 to your computer and use it in GitHub Desktop.
How to get the JSON file from a KeyCloak server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.keycloak.forge.addon; | |
import java.util.List; | |
import org.junit.Test; | |
import org.keycloak.admin.client.Keycloak; | |
import org.keycloak.admin.client.KeycloakBuilder; | |
import org.keycloak.admin.client.resource.ClientResource; | |
import org.keycloak.admin.client.resource.ClientsResource; | |
import org.keycloak.representations.idm.ClientRepresentation; | |
/** | |
* Created by ggastald on 15/06/16. | |
*/ | |
public class KeycloakClientTest { | |
@Test | |
public void test() { | |
String serverUrl = "http://localhost:9000/auth"; | |
String realm = "master"; | |
String clientId = "security-admin-console"; | |
String providerId = "keycloak-oidc-keycloak-json"; | |
String user = "admin"; | |
String password = "admin"; | |
// Make sure that Direct Access Grants Enabled is enabled for the given clientId | |
Keycloak kc = KeycloakBuilder.builder() | |
.serverUrl(serverUrl) | |
.realm(realm) | |
.clientId(clientId) | |
.username(user) | |
.password(password) | |
.build(); | |
ClientsResource clientsResource = kc.realm(realm).clients(); | |
List<ClientRepresentation> clientRepresentationList = clientsResource.findByClientId(clientId); | |
ClientRepresentation clientRepresentation = clientRepresentationList.get(0); | |
ClientResource clientResource = clientsResource.get(clientRepresentation.getId()); | |
System.out.println(clientResource.getInstallationProvider(providerId)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment