Skip to content

Commit 2e14b3e

Browse files
authored
Feature/teja/539 (#541)
1 parent 58182fb commit 2e14b3e

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,44 @@ public Request<List<MfaAuthenticator>> listAuthenticators(String accessToken) {
12321232
return request;
12331233
}
12341234

1235+
/**
1236+
* Deletes an associated authenticator using its ID.
1237+
* <pre>
1238+
* {@code
1239+
* try {
1240+
* authAPI.deleteAuthenticator("token", "deviceId")
1241+
* .execute()
1242+
* .getBody();
1243+
* } catch (Auth0Exception e) {
1244+
* //Something happened
1245+
* }
1246+
* }
1247+
* </pre>
1248+
*
1249+
* @param accessToken The Access Token obtained during login. The token must possess a scope of {@code remove:authenticators}
1250+
* and an audience of {@code https://YOUR_DOMAIN/mfa/}
1251+
* @param authenticatorId The unique identifier associated with the authenticator. We can obtain the authenticatorIds by making a
1252+
* call to {@code listAuthenticators} method in this api.
1253+
* @return a Request to execute.
1254+
* @see <a href="https://auth0.com/docs/api/authentication#delete-an-authenticator">Delete authenticators API documentation</a>
1255+
*/
1256+
public Request<Void> deleteAuthenticator(String accessToken, String authenticatorId) {
1257+
Asserts.assertNotNull(accessToken, "access token");
1258+
Asserts.assertNotNull(authenticatorId, "authenticator id");
1259+
1260+
String url = baseUrl
1261+
.newBuilder()
1262+
.addPathSegment("mfa")
1263+
.addPathSegment("authenticators")
1264+
.addPathSegment(authenticatorId)
1265+
.build()
1266+
.toString();
1267+
1268+
VoidRequest request = new VoidRequest(client, null, url, HttpMethod.DELETE);
1269+
request.addHeader("Authorization", "Bearer " + accessToken);
1270+
return request;
1271+
}
1272+
12351273
private TokenRequest exchangeCode(String code, String redirectUri, boolean secretRequired) {
12361274
Asserts.assertNotNull(code, "code");
12371275
Asserts.assertNotNull(redirectUri, "redirect uri");

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,35 @@ public void listAuthenticatorsRequest() throws Exception {
14841484
assertThat(response, is(notNullValue()));
14851485
}
14861486

1487+
@Test
1488+
public void deleteAuthenticatorThrowsWhenTokenNull() {
1489+
exception.expect(IllegalArgumentException.class);
1490+
exception.expectMessage("'access token' cannot be null!");
1491+
api.deleteAuthenticator(null, "authenticatorId");
1492+
}
1493+
1494+
@Test
1495+
public void deleteAuthenticatorThrowsWhenAuthenticatorIdNull() {
1496+
exception.expect(IllegalArgumentException.class);
1497+
exception.expectMessage("'authenticator id' cannot be null!");
1498+
api.deleteAuthenticator("Bearer accessToken", null);
1499+
}
1500+
1501+
@Test
1502+
public void deleteAuthenticatorRequest() throws Exception {
1503+
Request<Void> request = api.deleteAuthenticator("accessToken", "authenticatorId");
1504+
1505+
server.jsonResponse(AUTH_LIST_AUTHENTICATORS_RESPONSE, 200);
1506+
Void response = request.execute().getBody();
1507+
RecordedRequest recordedRequest = server.takeRequest();
1508+
1509+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.DELETE, "/mfa/authenticators/authenticatorId"));
1510+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
1511+
assertThat(recordedRequest, hasHeader("Authorization", "Bearer accessToken"));
1512+
1513+
assertThat(response, is(nullValue()));
1514+
}
1515+
14871516
@Test
14881517
public void challengeRequestThrowsWhenTokenNull() {
14891518
exception.expect(IllegalArgumentException.class);

0 commit comments

Comments
 (0)