Skip to content

Commit 1dd0a5f

Browse files
authored
Support delete all authentication methods endpoint (#645)
1 parent 845fedb commit 1dd0a5f

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/main/java/com/auth0/client/mgmt/UsersEntity.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,28 @@ public Request<Void> deleteAuthenticationMethodById(String userId, String authen
735735
return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE);
736736
}
737737

738+
/**
739+
* Deletes all authentication methods for the given user.
740+
* A token with scope {@code delete:authentication_methods} is needed.
741+
* @see <a href="https://auth0.com/docs/api/management/v2/users/delete-authentication-methods">https://auth0.com/docs/api/management/v2/users/delete-authentication-methods</a>
742+
*
743+
* @param userId the user to delete the authentication method for
744+
* @return a Request to execute.
745+
*/
746+
public Request<Void> deleteAllAuthenticationMethods(String userId) {
747+
Asserts.assertNotNull(userId, "user ID");
748+
749+
String url = baseUrl
750+
.newBuilder()
751+
.addPathSegments("api/v2/users")
752+
.addPathSegment(userId)
753+
.addPathSegment("authentication-methods")
754+
.build()
755+
.toString();
756+
757+
return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE);
758+
}
759+
738760
/**
739761
* Updates an authentication method.
740762
* A token with scope {@code update:authentication_methods} is needed.

src/test/java/com/auth0/client/mgmt/UsersEntityTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,26 @@ public void shouldDeleteUserAuthenticationMethodById() throws Exception {
13091309
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
13101310
}
13111311

1312+
@Test
1313+
public void shouldNotDeleteAllAuthenticationMethodsWithNullUserId() {
1314+
verifyThrows(IllegalArgumentException.class,
1315+
() -> api.users().deleteAllAuthenticationMethods(null),
1316+
"'user ID' cannot be null!");
1317+
}
1318+
1319+
@Test
1320+
public void shouldDeleteAllAuthenticationMethods() throws Exception {
1321+
Request<Void> request = api.users().deleteAllAuthenticationMethods("1");
1322+
assertThat(request, is(notNullValue()));
1323+
1324+
server.noContentResponse();
1325+
request.execute().getBody();
1326+
RecordedRequest recordedRequest = server.takeRequest();
1327+
1328+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/users/1/authentication-methods"));
1329+
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
1330+
}
1331+
13121332
@Test
13131333
public void invalidateRememberedBrowsersThrowsWhenUserIdIsNull() {
13141334
verifyThrows(IllegalArgumentException.class,

0 commit comments

Comments
 (0)