Org.keycloak.admin.client and keycloak setup

I have hours ferkeling with code and am struggling to get a connection, by code, through to kecycloak.

//    	Keycloak keycloak = KeycloakBuilder.builder() //
//				.serverUrl(keycloakServerURL+"/auth") //
//				.realm("master")//
//				.username("") //
//				.password("password") //
//				.clientId("xxxxxx") //
//				.clientSecret("====================")
//				.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) //
//				.build();
//    	// (serverUrl, realm, clientId, authToken)
		Keycloak keycloak = Keycloak.getInstance(
//    	Keycloak keycloak = KeycloakBuilder.builder() //
//				.serverUrl(keycloakServerURL+"/auth") //
//				.realm("TheREALMTOCONNECTTO")//
//				.username(") //
//				.password("password") //
//				.grantType(OAuth2Constants.CLIENT_CREDENTIALS) //
//				.clientSecret("THESECRET")
//				.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()) //
//				.build();
			RealmResource realmResource = keycloak.realm("TheREALMTOCONNECTTO");
			RealmRepresentation realm = realmResource.toRepresentation();
			List<UserRepresentation> users = realm.getUsers();"Number of users:" + users.size());
			return users;

Please can someone tell me what/who to set up in a NEW realm in Keycloak (8.0.2) such that I can actually get a connection.

From the hours of googling I think you have to set up a user in the new realm with certainroles/rights/privledges/scopes/??? and then the call has to authenticate somehow.

(from the code aboce; sometimes I get a 401 and sometimes a NPE depending how I cut the code and change settings in web.xml and standalone.xml



    <auth-method>BASIC</auth-method> <-- **Changing this to KEYCLOAK seems to haev effects**



   <subsystem xmlns="urn:jboss:domain:keycloak:1.1">
  	<secure-deployment name="theplanetsparty.war">
  		<resource>xxxxxx</resource> <-- cahnging the user has effects
  		<credential name="secret">xxxxxx</credential>   <-- Adding / removing this has effects

Any help would be appreciated…

The server is Wildfly 18.0.1.Final
The getting started docuementation was used to set up the server and the code is working fin (JSF project that jumps off to keycloak … and I have set up Goole auth etc.).

I need this to remove/add a role to a user (one they have become a member)…

Also; how do you get the “cancel” button (Login/Register) to come back to my server (only sumbit ends up coming back to the server)?

Some additional resources:

Ill just have to use stright REST calls.

Try Postman :slight_smile:


Ref: Flowable OAuth2 Resource Server