Skip to content

Commit 318babc

Browse files
authored
Added organization support for Change Password (#726)
1 parent e6c054d commit 318babc

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/main/java/com/auth0/client/auth/AuthAPI.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,31 @@ public Request<Void> resetPassword(String email, String connection) {
525525
* @return a Request to execute.
526526
*/
527527
public Request<Void> resetPassword(String clientId, String email, String connection) {
528+
return resetPassword(clientId, email, connection, null);
529+
}
530+
531+
/**
532+
* Request a password reset for the given client ID, email, database connection and organization ID. The response will always be successful even if
533+
* there's no user associated to the given email for that database connection.
534+
* i.e.:
535+
* <pre>
536+
* {@code
537+
* try {
538+
* authAPI.resetPassword("CLIENT-ID", "me@auth0.com", "db-connection", "ORGANIZATION-ID").execute().getBody();
539+
* } catch (Auth0Exception e) {
540+
* //Something happened
541+
* }
542+
* }
543+
* </pre>
544+
*
545+
* @see <a href="https://auth0.com/docs/api/authentication#change-password">Change Password API docs</a>
546+
* @param clientId the client ID of your client.
547+
* @param email the email associated to the database user.
548+
* @param connection the database connection where the user was created.
549+
* @param organization the organization ID where the user was created.
550+
* @return a Request to execute.
551+
*/
552+
public Request<Void> resetPassword(String clientId, String email, String connection, String organization) {
528553
Asserts.assertNotNull(email, "email");
529554
Asserts.assertNotNull(connection, "connection");
530555

@@ -538,6 +563,7 @@ public Request<Void> resetPassword(String clientId, String email, String connect
538563
request.addParameter(KEY_CLIENT_ID, clientId);
539564
request.addParameter(KEY_EMAIL, email);
540565
request.addParameter(KEY_CONNECTION, connection);
566+
request.addParameter(KEY_ORGANIZATION, organization);
541567
return request;
542568
}
543569

src/test/java/com/auth0/client/auth/AuthAPITest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,28 @@ public void shouldCreateResetPasswordRequestWithSpecifiedClientId() throws Excep
328328
assertThat(response, is(nullValue()));
329329
}
330330

331+
@Test
332+
public void shouldCreateResetPasswordRequestWithSpecifiedClientIdWithOrganization() throws Exception {
333+
Request<Void> request = api.resetPassword("CLIENT-ID", "me@auth0.com", "db-connection", "ORGANIZATION-ID");
334+
assertThat(request, is(notNullValue()));
335+
336+
server.jsonResponse(AUTH_RESET_PASSWORD, 200);
337+
Void response = request.execute().getBody();
338+
RecordedRequest recordedRequest = server.takeRequest();
339+
340+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/dbconnections/change_password"));
341+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
342+
343+
Map<String, Object> body = bodyFromRequest(recordedRequest);
344+
assertThat(body, hasEntry("email", "me@auth0.com"));
345+
assertThat(body, hasEntry("connection", "db-connection"));
346+
assertThat(body, hasEntry("client_id", "CLIENT-ID"));
347+
assertThat(body, hasEntry("organization", "ORGANIZATION-ID"));
348+
assertThat(body, not(hasKey("password")));
349+
350+
assertThat(response, is(nullValue()));
351+
}
352+
331353
//Sign Up
332354

333355
@SuppressWarnings("deprecation")

0 commit comments

Comments
 (0)