Reputation: 23
I need a Java Keycloak(2.3) connection to return tokens, however I've ran into problems much earlier. When POST-requesting my Keycloak instance in Postman I get following errors in the particular console.
This is the example from Keycloak my code is based on.
Keycloak:
17:54:47,586 WARN [org.keycloak.events] (default task-25) type=LOGIN_ERROR, realmId=master, clientId=admin-cli, userId=null, ipAddress=127.0.0.1, error=invalid_client_credentials, grant_type=password
Wildfly:
17:55:14,310 ERROR [stderr] (default task-48) javax.ws.rs.BadRequestException: HTTP 400 Bad Request
Java:
Keycloak keycloak = Keycloak.getInstance(
KEYCLOAK_TOKEN_RESOURCE_URI,
REALM,
KEYCLOAK_USERNAME,
KEYCLOAK_PASSWORD,
KEYCLOAK_CLIENT);
RealmRepresentation realm = keycloak.realm(REALM).toRepresentation();
Upvotes: 1
Views: 2524
Reputation: 23
I was able to fix the issue by changing my java code to the following
Keycloak keycloak = KeycloakBuilder.builder()
.serverUrl(KEYCLOAK_TOKEN_RESOURCE_URI)
.realm(REALM)
.username(KEYCLOAK_USERNAME)
.password(KEYCLOAK_PASSWORD)
.clientId(KEYCLOAK_CLIENT)
.clientSecret(CLIENT_SECRET)
.build();
Upvotes: 1
Reputation: 124
Keycloak keycloak = KeycloakBuilder.builder().serverUrl(KEYCLOAK_TOKEN_RESOURCE_URI).realm(REALM)
.username(KEYCLOAK_USERNAME).password(KEYCLOAK_PASSWORD).clientId(KEYCLOAK_CLIENT)
.clientSecret("input-here-your-client-secret").build();
Maybe this should work, because Keycloak 2.3.Final has a Bug on the Keycloak.getInstance(...) method.
Upvotes: 0