I am trying to trigger the password-reset process in keycloack, such that the user receives an email to set a new password. Unfortunately I always get 400 response with
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: io.undertow.servlet.spec.ServletInputStreamImpl@89719e69; line: 1, column: 1]
I call keycloak on described api: "PUT /admin/realms/{realm}/users/{id}/execute-actions-email" with following object:
{"actions":["UPDATE_PASSWORD"]}
see: http://www.keycloak.org/docs/rest-api/index.html#_send_a_update_account_email_to_the_user
Solution: Use only ["UPDATE_PASSWORD"]
as body for your request and it works...
an in java: Entity.json("[\"UPDATE_PASSWORD\"]");
For all those who want to write REST call for execute-actions-email, here is the working code snippet -
CloseableHttpClient httpclient = HttpClients.createDefault();
AccessTokenResponse accessTokenResponse = authzClient.obtainAccessToken(adminUserName, adminPassword);
String urlResetPassword = keyCloakURL+"/admin/realms/"+realmName+"/users/"+userId+"/execute-actions-email";
HttpPut putRequest = new HttpPut(urlResetPassword);
accessTokenResponse = authzClient.obtainAccessToken(adminUserName, adminPassword);
putRequest.addHeader("Authorization", "bearer "+accessTokenResponse.getToken());
putRequest.addHeader("content-type", MediaType.APPLICATION_JSON);
putRequest.setHeader("Accept", MediaType.APPLICATION_JSON);
StringEntity jSonEntity = new StringEntity("[\"UPDATE_PASSWORD\"]");
putRequest.setEntity(jSonEntity);
CloseableHttpResponse response = httpclient.execute(putRequest);
Thanks.
Correct Request will be as below.
URL:http://{{HOSTNAME}}:{{PORT}}/auth/realms/{{REALM_NAME}}/users/{{USER_ID}}/execute-actions-email
HTTP-METHOD: PUT
BODY: ["UPDATE_PASSWORD"]
HEADERS: AUTHORIZATION BEARER {{TOKEN-GOES-HERE}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With