Skip to content

Commit ce28001

Browse files
Keep previous method but deprecate it
1 parent 8fe07a6 commit ce28001

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,54 @@ public Request<CreatedOtpResponse> addOtpAuthenticator(String mfaToken) {
14131413
* @param mfaToken The token received from mfa_required error. Must not be null.
14141414
* @param oobChannels The type of OOB channels supported by the client. Must not be null.
14151415
* @param phoneNumber The phone number for "sms" or "voice" channels. May be null if not using "sms" or "voice".
1416+
* @return a Request to execute.
1417+
* @see <a href="https://auth0.com/docs/api/authentication#add-an-authenticator">Add an Authenticator API documentation</a>
1418+
* @deprecated Use {@linkplain #addOobAuthenticator(String, List, String, String)} instead.
1419+
*/
1420+
@Deprecated
1421+
public Request<CreatedOobResponse> addOobAuthenticator(String mfaToken, List<String> oobChannels, String phoneNumber) {
1422+
Asserts.assertNotNull(mfaToken, "mfa token");
1423+
Asserts.assertNotNull(oobChannels, "OOB channels");
1424+
1425+
String url = baseUrl
1426+
.newBuilder()
1427+
.addPathSegment("mfa")
1428+
.addPathSegment("associate")
1429+
.build()
1430+
.toString();
1431+
1432+
BaseRequest<CreatedOobResponse> request = new BaseRequest<>(client, null, url, HttpMethod.POST, new TypeReference<CreatedOobResponse>() {
1433+
});
1434+
1435+
request.addParameter("authenticator_types", Collections.singletonList("oob"));
1436+
request.addParameter("oob_channels", oobChannels);
1437+
request.addParameter(KEY_CLIENT_ID, clientId);
1438+
if (phoneNumber != null) {
1439+
request.addParameter("phone_number", phoneNumber);
1440+
}
1441+
addClientAuthentication(request, false);
1442+
request.addHeader("Authorization", "Bearer " + mfaToken);
1443+
return request;
1444+
}
1445+
1446+
/**
1447+
* Associates or adds a new OOB authenticator for multi-factor authentication (MFA).
1448+
* Confidential clients (Regular Web Apps) <strong>must</strong> have a client secret configured on this {@code AuthAPI} instance.
1449+
* <pre>
1450+
* {@code
1451+
* try {
1452+
* CreatedOobResponse result = authAPI.addOobAuthenticator("the-mfa-token", Arrays.asList("sms", "email"), "phone-number", "email-address")
1453+
* .execute()
1454+
* .getBody();
1455+
* } catch (Auth0Exception e) {
1456+
* //Something happened
1457+
* }
1458+
* }
1459+
* </pre>
1460+
*
1461+
* @param mfaToken The token received from mfa_required error. Must not be null.
1462+
* @param oobChannels The type of OOB channels supported by the client. Must not be null.
1463+
* @param phoneNumber The phone number for "sms" or "voice" channels. May be null if not using "sms" or "voice".
14161464
* @param emailAddress The email address for "email" channel. May be null if not using "email".
14171465
* @return a Request to execute.
14181466
* @see <a href="https://auth0.com/docs/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-challenge-sms-voice-authenticators#enroll-with-sms-or-voice">Enroll with SMS or voice</a>

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,20 +1548,47 @@ public void addOobAuthenticatorThrowsWhenTokenNull() {
15481548
"'mfa token' cannot be null!");
15491549
}
15501550

1551+
@SuppressWarnings("deprecation")
15511552
@Test
15521553
public void addOobAuthenticatorThrowsWhenChannelsNull() {
15531554
verifyThrows(IllegalArgumentException.class,
1554-
() -> api.addOobAuthenticator("mfaToken", null, null, null),
1555+
() -> api.addOobAuthenticator("mfaToken", null, null),
15551556
"'OOB channels' cannot be null!");
15561557
}
15571558

1559+
@SuppressWarnings("deprecation")
15581560
@Test
15591561
public void addOobAuthenticatorThrowsWhenPhoneNumberNull() {
15601562
verifyThrows(IllegalArgumentException.class,
15611563
() -> api.addOobAuthenticator("mfaToken", Collections.singletonList("sms"), null, null),
15621564
"'phone number' cannot be null!");
15631565
}
15641566

1567+
@SuppressWarnings("deprecation")
1568+
@Test
1569+
public void addOobAuthenticatorRequest() throws Exception {
1570+
Request<CreatedOobResponse> request = api.addOobAuthenticator("mfaToken", Collections.singletonList("sms"), "phone-number");
1571+
1572+
server.jsonResponse(AUTH_OOB_AUTHENTICATOR_RESPONSE, 200);
1573+
CreatedOobResponse response = request.execute().getBody();
1574+
RecordedRequest recordedRequest = server.takeRequest();
1575+
1576+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/mfa/associate"));
1577+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
1578+
1579+
Map<String, Object> body = bodyFromRequest(recordedRequest);
1580+
assertThat(body, hasEntry("authenticator_types", Collections.singletonList("oob")));
1581+
assertThat(body, hasEntry("oob_channels", Collections.singletonList("sms")));
1582+
assertThat(body, hasEntry("phone_number", "phone-number"));
1583+
1584+
assertThat(response, is(notNullValue()));
1585+
assertThat(response.getAuthenticatorType(), not(emptyOrNullString()));
1586+
assertThat(response.getOobChannel(), not(emptyOrNullString()));
1587+
assertThat(response.getOobCode(), not(emptyOrNullString()));
1588+
assertThat(response.getBarcodeUri(), not(emptyOrNullString()));
1589+
assertThat(response.getRecoveryCodes(), notNullValue());
1590+
}
1591+
15651592
@Test
15661593
public void addOobAuthenticatorThrowsWhenEmailNull() {
15671594
verifyThrows(IllegalArgumentException.class,
@@ -1570,7 +1597,7 @@ public void addOobAuthenticatorThrowsWhenEmailNull() {
15701597
}
15711598

15721599
@Test
1573-
public void addOobAuthenticatorRequest() throws Exception {
1600+
public void addOobAuthenticatorRequestWithEmail() throws Exception {
15741601
Request<CreatedOobResponse> request = api.addOobAuthenticator("mfaToken", Arrays.asList("sms", "email"), "phone-number", "email-address");
15751602

15761603
server.jsonResponse(AUTH_OOB_AUTHENTICATOR_RESPONSE, 200);

0 commit comments

Comments
 (0)