[keycloak-user] Setting Password for Users.

PAA KOJO KONDUAH AMOS pkkamos at gmail.com
Tue Jan 5 04:08:48 EST 2016


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.

Sent from Mail for Windows 10


From: Stian Thorgersen
Sent: Tuesday, January 5, 2016 7:33 AM
To: PAA KOJO KONDUAH AMOS
Cc: keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] Setting Password for Users.

That looks correct to me. What status code do you get back? Any errors in the log?

On 5 January 2016 at 07:51, PAA KOJO KONDUAH AMOS <pkkamos at gmail.com> wrote:
Hello.
 
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.
 
Please can anyone show me a sample code for password reset?
 
This is what I have so far:
 
URL: http://localhost:8888/auth/admin/realms/crusadersterling/users/
 
public void resetPassword(String userId, String token) throws IOException, Failure {
 
                              CredentialRepresentation credential = new CredentialRepresentation();
                              credential.setType(CredentialRepresentation.PASSWORD);
                              credential.setValue("123456");
                              credential.setTemporary(true);
 
                              HttpClient client = HttpClientBuilder.create().build();
                              ObjectMapper mapper = new ObjectMapper();
                              String json = null;
                              try {
                                             String usesUrl = PropertiesUtil.getValue("reset_password");
                                             HttpPut put = new HttpPut(usesUrl + userId + "/reset-password");
                                             put.addHeader("Authorization", "Bearer " + token);
                                             put.setHeader("Content-Type", "application/json");
                                             put.setHeader("Accept", "application/json");
                                             json = mapper.writeValueAsString(credential);
                                             StringEntity entity = new StringEntity(json);
                                             put.setEntity(entity);
                                             try {
                                                            HttpResponse response = client.execute(put);
 
                                                            
 
                                                            if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith("20")) {
                                                                           System.err.println(response.getStatusLine().getReasonPhrase());
                                                                           throw new Failure(response.getStatusLine().getStatusCode());
                                                            }
 
                                             } catch (IOException | Failure | IllegalStateException e) {
 
                                                            throw e;
                                             }
                              } catch (IOException e) {
                                             throw new RuntimeException(e);
                              } finally {
                                             client.getConnectionManager().shutdown();
                              }
                              
               }
 
Sent from Mail for Windows 10
 

_______________________________________________
keycloak-user mailing list
keycloak-user at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160105/3f6d126b/attachment-0001.html 


More information about the keycloak-user mailing list