Skip to content

Commit 26bcd0f

Browse files
committed
Merge branch 'master' into sdk-5211-custom-prompts
2 parents 4d13440 + 9c484d3 commit 26bcd0f

File tree

7 files changed

+104
-2
lines changed

7 files changed

+104
-2
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class AuthAPI {
6868
private static final String PATH_PASSWORDLESS = "passwordless";
6969
private static final String PATH_START = "start";
7070
private static final String KEY_ORGANIZATION = "organization";
71+
private static final String KEY_PHONE_NUMBER = "phone_number";
7172

7273
private final Auth0HttpClient client;
7374
private final String clientId;
@@ -485,6 +486,41 @@ public Request<Void> resetPassword(String clientId, String email, String connect
485486
return request;
486487
}
487488

489+
/**
490+
* Creates a sign up request with the given credentials, phone number and database connection.
491+
* "Requires Username" option must be turned on in the Connection's configuration first.
492+
* i.e.:
493+
* <pre>
494+
* {@code
495+
* try {
496+
* Map<String, String> fields = new HashMap<String, String>();
497+
* fields.put("age", "25);
498+
* fields.put("city", "Buenos Aires");
499+
* authAPI.signUp("me@auth0.com", "myself", new char[]{'s','e','c','r','e','t'}, "db-connection", "1234567890")
500+
* .setCustomFields(fields)
501+
* .execute();
502+
* } catch (Auth0Exception e) {
503+
* //Something happened
504+
* }
505+
* }
506+
* </pre>
507+
*
508+
* @see <a href="https://auth0.com/docs/api/authentication#signup">Signup API docs</a>
509+
* @param email the desired user's email.
510+
* @param username the desired user's username.
511+
* @param password the desired user's password.
512+
* @param connection the database connection where the user is going to be created.
513+
* @param phoneNumber the desired users's phone number.
514+
* @return a Request to configure and execute.
515+
*/
516+
public SignUpRequest signUp(String email, String username, char[] password, String connection, String phoneNumber) {
517+
Asserts.assertNotNull(phoneNumber, "phone number");
518+
519+
SignUpRequest request = this.signUp(email, username, password, connection);
520+
request.addParameter(KEY_PHONE_NUMBER, phoneNumber);
521+
return request;
522+
}
523+
488524
/**
489525
* Creates a sign up request with the given credentials and database connection.
490526
* "Requires Username" option must be turned on in the Connection's configuration first.

src/main/java/com/auth0/json/auth/CreatedUser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class CreatedUser {
2222
private String username;
2323
@JsonProperty("email_verified")
2424
private Boolean emailVerified;
25+
@JsonProperty("phone_number")
26+
private String phoneNumber;
2527

2628
@JsonProperty("_id")
2729
@JsonAlias({"_id", "id", "user_id"})
@@ -44,4 +46,8 @@ public Boolean isEmailVerified() {
4446
return emailVerified;
4547
}
4648

49+
@JsonProperty("phone_number")
50+
public String getPhoneNumber() {
51+
return phoneNumber;
52+
}
4753
}

src/main/java/com/auth0/json/mgmt/organizations/EnabledConnection.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class EnabledConnection {
2020
private String connectionId;
2121
@JsonProperty("show_as_button")
2222
private Boolean showAsButton;
23+
@JsonProperty("is_signup_enabled")
24+
private Boolean isSignupEnabled;
2325

2426
public EnabledConnection() {}
2527

@@ -95,4 +97,19 @@ public Boolean getShowAsButton() {
9597
public void setShowAsButton(Boolean showAsButton) {
9698
this.showAsButton = showAsButton;
9799
}
100+
101+
/**
102+
* @return whether signup is enabled for this connection.
103+
*/
104+
public Boolean getSignupEnabled() {
105+
return isSignupEnabled;
106+
}
107+
108+
/**
109+
* Sets whether signup is enabled for this connection.
110+
* @param signupEnabled {@code true} to enable signup, {@code false} to disable it.
111+
*/
112+
public void setSignupEnabled(Boolean signupEnabled) {
113+
isSignupEnabled = signupEnabled;
114+
}
98115
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ public void shouldThrowOnUsernameSignUpWithNullConnection() {
400400
"'connection' cannot be null!");
401401
}
402402

403+
@Test
404+
public void shouldThrowOnUsernameAndPhoneNumberSignUpWithNullPhoneNumber() {
405+
verifyThrows(IllegalArgumentException.class,
406+
() -> api.signUp("me@auth0.com", "me", new char[]{'p','4','5','5','w','0','r','d'}, "my-connection", null),
407+
"'phone number' cannot be null!");
408+
}
409+
403410
@Test
404411
public void shouldHaveNotStrongPasswordWithDetailedDescription() throws Exception {
405412
ObjectMapper mapper = new ObjectMapper();
@@ -424,6 +431,34 @@ public void shouldHaveNotStrongPasswordWithShortDetailedDescription() throws Exc
424431
assertThat(ex.getDescription(), is(expectedDescription));
425432
}
426433

434+
@Test
435+
public void shouldCreateSignUpRequestWithUsernameAndPhoneNumber() throws Exception {
436+
SignUpRequest request = api.signUp("me@auth0.com", "me", new char[]{'p','4','5','5','w','0','r','d'}, "db-connection", "1234567890");
437+
assertThat(request, is(notNullValue()));
438+
439+
server.jsonResponse(AUTH_SIGN_UP_USERNAME, 200);
440+
CreatedUser response = request.execute().getBody();
441+
RecordedRequest recordedRequest = server.takeRequest();
442+
443+
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/dbconnections/signup"));
444+
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
445+
446+
Map<String, Object> body = bodyFromRequest(recordedRequest);
447+
assertThat(body, hasEntry("email", "me@auth0.com"));
448+
assertThat(body, hasEntry("username", "me"));
449+
assertThat(body, hasEntry("password", "p455w0rd"));
450+
assertThat(body, hasEntry("connection", "db-connection"));
451+
assertThat(body, hasEntry("client_id", CLIENT_ID));
452+
assertThat(body, hasEntry("phone_number", "1234567890"));
453+
454+
assertThat(response, is(notNullValue()));
455+
assertThat(response.getUserId(), is("58457fe6b27"));
456+
assertThat(response.getEmail(), is("me@auth0.com"));
457+
assertThat(response.isEmailVerified(), is(false));
458+
assertThat(response.getUsername(), is("me"));
459+
assertThat(response.getPhoneNumber(), is("1234567890"));
460+
}
461+
427462
@Test
428463
public void shouldCreateSignUpRequestWithUsername() throws Exception {
429464
@SuppressWarnings("deprecation")

src/test/java/com/auth0/json/mgmt/organizations/EnabledConnectionsPageTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class EnabledConnectionsPageTest extends JsonTest<EnabledConnectionsPage>
1212
" {\n" +
1313
" \"connection_id\": \"con_1\",\n" +
1414
" \"assign_membership_on_login\": false,\n" +
15+
" \"is_signup_enabled\": true,\n" +
1516
" \"connection\": {\n" +
1617
" \"name\": \"google-oauth2\",\n" +
1718
" \"strategy\": \"google-oauth2\"\n" +
@@ -20,6 +21,7 @@ public class EnabledConnectionsPageTest extends JsonTest<EnabledConnectionsPage>
2021
" {\n" +
2122
" \"connection_id\": \"con_2\",\n" +
2223
" \"assign_membership_on_login\": true,\n" +
24+
" \"is_signup_enabled\": true,\n" +
2325
" \"connection\": {\n" +
2426
" \"name\": \"Username-Password-Authentication\",\n" +
2527
" \"strategy\": \"auth0\"\n" +
@@ -32,6 +34,7 @@ public class EnabledConnectionsPageTest extends JsonTest<EnabledConnectionsPage>
3234
" {\n" +
3335
" \"connection_id\": \"con_1\",\n" +
3436
" \"assign_membership_on_login\": false,\n" +
37+
" \"is_signup_enabled\": true,\n" +
3538
" \"connection\": {\n" +
3639
" \"name\": \"google-oauth2\",\n" +
3740
" \"strategy\": \"google-oauth2\"\n" +
@@ -40,6 +43,7 @@ public class EnabledConnectionsPageTest extends JsonTest<EnabledConnectionsPage>
4043
" {\n" +
4144
" \"connection_id\": \"con_2\",\n" +
4245
" \"assign_membership_on_login\": true,\n" +
46+
" \"is_signup_enabled\": true,\n" +
4347
" \"connection\": {\n" +
4448
" \"name\": \"Username-Password-Authentication\",\n" +
4549
" \"strategy\": \"auth0\"\n" +

src/test/java/com/auth0/json/mgmt/organizations/EnabledConnectionsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void shouldSerialize() throws Exception {
2222
EnabledConnection enabledConnection = new EnabledConnection();
2323
enabledConnection.setAssignMembershipOnLogin(true);
2424
enabledConnection.setConnection(connection);
25+
enabledConnection.setSignupEnabled(true);
2526

2627
String serialized = toJSON(enabledConnection);
2728
assertThat(serialized, is(notNullValue()));
@@ -39,6 +40,7 @@ public void shouldDeserialize() throws Exception {
3940
String json = "{\n" +
4041
" \"connection_id\": \"con_id\",\n" +
4142
" \"assign_membership_on_login\": false,\n" +
43+
" \"is_signup_enabled\": true,\n" +
4244
" \"connection\": {\n" +
4345
" \"name\": \"google-oauth2\",\n" +
4446
" \"strategy\": \"google-oauth2\"\n" +
@@ -49,6 +51,7 @@ public void shouldDeserialize() throws Exception {
4951
assertThat(enabledConnection, is(notNullValue()));
5052
assertThat(enabledConnection.getConnectionId(), is("con_id"));
5153
assertThat(enabledConnection.isAssignMembershipOnLogin(), is(false));
54+
assertThat(enabledConnection.getSignupEnabled(), is(true));
5255
assertThat(enabledConnection.getConnection(), is(notNullValue()));
5356
assertThat(enabledConnection.getConnection().getName(), is("google-oauth2"));
5457
assertThat(enabledConnection.getConnection().getStrategy(), is("google-oauth2"));

src/test/resources/auth/sign_up_username.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"_id": "58457fe6b27",
33
"email_verified": false,
44
"email": "me@auth0.com",
5-
"username": "me"
6-
}
5+
"username": "me",
6+
"phone_number": "1234567890"
7+
}

0 commit comments

Comments
 (0)