<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>There are no errors at all. The user gets created nicely. It is the credentials part which doesn’t take effect. So when I log in. it says Invalid Username/Password.<o:p></o:p></p><p class=MsoNormal><o:p> </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> </o:p></span></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;border:none;padding:0in'><br><b>From: </b><a href="mailto:sthorger@redhat.com">Stian Thorgersen</a><br><b>Sent: </b>Tuesday, January 5, 2016 7:33 AM<br><b>To: </b><a href="mailto:pkkamos@gmail.com">PAA KOJO KONDUAH AMOS</a><br><b>Cc: </b><a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br><b>Subject: </b>Re: [keycloak-user] Setting Password for Users.</p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>That looks correct to me. What status code do you get back? Any errors in the log?</span><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>On 5 January 2016 at 07:51, PAA KOJO KONDUAH AMOS <<a href="mailto:pkkamos@gmail.com" target="_blank">pkkamos@gmail.com</a>> wrote:<o:p></o:p></span></p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal>Hello.<o:p></o:p></p><p class=MsoNormal> </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> </p><p class=MsoNormal>Please can anyone show me a sample code for password reset?</p><p class=MsoNormal> </p><p class=MsoNormal>This is what I have so far:</p><p class=MsoNormal> </p><p class=MsoNormal><b>URL: <a href="http://localhost:8888/auth/admin/realms/crusadersterling/users/" target="_blank">http://localhost:8888/auth/admin/realms/crusadersterling/users/</a></b></p><p class=MsoNormal> </p><p class=MsoNormal>public void resetPassword(String userId, String token) throws IOException, Failure {</p><p class=MsoNormal> </p><p class=MsoNormal> <b>CredentialRepresentation credential = new CredentialRepresentation();</b></p><p class=MsoNormal><b> credential.setType(CredentialRepresentation.PASSWORD);</b></p><p class=MsoNormal><b> credential.setValue("123456");</b></p><p class=MsoNormal><b> credential.setTemporary(true);</b></p><p class=MsoNormal> </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("reset_password");</p><p class=MsoNormal> HttpPut put = new HttpPut(usesUrl + userId + "/reset-password");</p><p class=MsoNormal> put.addHeader("Authorization", "Bearer " + token);</p><p class=MsoNormal> put.setHeader("Content-Type", "application/json");</p><p class=MsoNormal> put.setHeader("Accept", "application/json");</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> </p><p class=MsoNormal> </p><p class=MsoNormal> </p><p class=MsoNormal> if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith("20")) {</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> </p><p class=MsoNormal> } catch (IOException | Failure | IllegalStateException e) {</p><p class=MsoNormal> </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> </p><p class=MsoNormal>Sent from <a href="http://go.microsoft.com/fwlink/?LinkId=550986" target="_blank">Mail</a> for Windows 10</p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span></p></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><br>_______________________________________________<br>keycloak-user mailing list<br><a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><o:p></o:p></span></p></blockquote></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>