Skip to content

Commit

Permalink
Support delete all authentication methods endpoint (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames committed May 29, 2024
1 parent 845fedb commit 1dd0a5f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/auth0/client/mgmt/UsersEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,28 @@ public Request<Void> deleteAuthenticationMethodById(String userId, String authen
return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE);
}

/**
* Deletes all authentication methods for the given user.
* A token with scope {@code delete:authentication_methods} is needed.
* @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>
*
* @param userId the user to delete the authentication method for
* @return a Request to execute.
*/
public Request<Void> deleteAllAuthenticationMethods(String userId) {
Asserts.assertNotNull(userId, "user ID");

String url = baseUrl
.newBuilder()
.addPathSegments("api/v2/users")
.addPathSegment(userId)
.addPathSegment("authentication-methods")
.build()
.toString();

return new VoidRequest(this.client, tokenProvider, url, HttpMethod.DELETE);
}

/**
* Updates an authentication method.
* A token with scope {@code update:authentication_methods} is needed.
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/auth0/client/mgmt/UsersEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,26 @@ public void shouldDeleteUserAuthenticationMethodById() throws Exception {
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
}

@Test
public void shouldNotDeleteAllAuthenticationMethodsWithNullUserId() {
verifyThrows(IllegalArgumentException.class,
() -> api.users().deleteAllAuthenticationMethods(null),
"'user ID' cannot be null!");
}

@Test
public void shouldDeleteAllAuthenticationMethods() throws Exception {
Request<Void> request = api.users().deleteAllAuthenticationMethods("1");
assertThat(request, is(notNullValue()));

server.noContentResponse();
request.execute().getBody();
RecordedRequest recordedRequest = server.takeRequest();

assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/api/v2/users/1/authentication-methods"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
}

@Test
public void invalidateRememberedBrowsersThrowsWhenUserIdIsNull() {
verifyThrows(IllegalArgumentException.class,
Expand Down

0 comments on commit 1dd0a5f

Please sign in to comment.