<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hello.</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>I am using Keycloak admin client version 1.7.0. Final to create users from an external application. I am able to create Users (with user.setEnabled set to true)and set the password as well. However, when I try to login it fails.</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>Please can anyone show me a sample code for password reset?</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>This is what I have so far:</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><b>URL: http://localhost:8888/auth/admin/realms/crusadersterling/users/<o:p></o:p></b></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>public void resetPassword(String userId, String token) throws IOException, Failure {</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>                              <b>CredentialRepresentation credential = new CredentialRepresentation();<o:p></o:p></b></p><p class=MsoNormal><b>                              credential.setType(CredentialRepresentation.PASSWORD);<o:p></o:p></b></p><p class=MsoNormal><b>                              credential.setValue(&quot;123456&quot;);<o:p></o:p></b></p><p class=MsoNormal><b>                              credential.setTemporary(true);<o:p></o:p></b></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>                              HttpClient client = HttpClientBuilder.create().build();</p><p class=MsoNormal>                              ObjectMapper mapper = new ObjectMapper();</p><p class=MsoNormal>                              String json = null;</p><p class=MsoNormal>                              try {</p><p class=MsoNormal>                                             String usesUrl = PropertiesUtil.getValue(&quot;reset_password&quot;);</p><p class=MsoNormal>                                             HttpPut put = new HttpPut(usesUrl + userId + &quot;/reset-password&quot;);</p><p class=MsoNormal>                                             put.addHeader(&quot;Authorization&quot;, &quot;Bearer &quot; + token);</p><p class=MsoNormal>                                             put.setHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);</p><p class=MsoNormal>                                             put.setHeader(&quot;Accept&quot;, &quot;application/json&quot;);</p><p class=MsoNormal>                                             json = mapper.writeValueAsString(credential);</p><p class=MsoNormal>                                             StringEntity entity = new StringEntity(json);</p><p class=MsoNormal>                                             put.setEntity(entity);</p><p class=MsoNormal>                                             try {</p><p class=MsoNormal>                                                            HttpResponse response = client.execute(put);</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>                                                            </p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>                                                            if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith(&quot;20&quot;)) {</p><p class=MsoNormal>                                                                           System.err.println(response.getStatusLine().getReasonPhrase());</p><p class=MsoNormal>                                                                           throw new Failure(response.getStatusLine().getStatusCode());</p><p class=MsoNormal>                                                            }</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>                                             } catch (IOException | Failure | IllegalStateException e) {</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>                                                            throw e;</p><p class=MsoNormal>                                             }</p><p class=MsoNormal>                              } catch (IOException e) {</p><p class=MsoNormal>                                             throw new RuntimeException(e);</p><p class=MsoNormal>                              } finally {</p><p class=MsoNormal>                                             client.getConnectionManager().shutdown();</p><p class=MsoNormal>                              }</p><p class=MsoNormal>                              </p><p class=MsoNormal>               }</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Sent from <a href="http://go.microsoft.com/fwlink/?LinkId=550986">Mail</a> for Windows 10</p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></p></div></body></html>