-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added phonenumber identifier in Auth API
- Loading branch information
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ public class AuthAPI { | |
private static final String PATH_PASSWORDLESS = "passwordless"; | ||
private static final String PATH_START = "start"; | ||
private static final String KEY_ORGANIZATION = "organization"; | ||
private static final String KEY_PHONE_NUMBER = "phone_number"; | ||
|
||
private final Auth0HttpClient client; | ||
private final String clientId; | ||
|
@@ -485,6 +486,41 @@ public Request<Void> resetPassword(String clientId, String email, String connect | |
return request; | ||
} | ||
|
||
/** | ||
* Creates a sign up request with the given credentials, phone number and database connection. | ||
* "Requires Username" option must be turned on in the Connection's configuration first. | ||
* i.e.: | ||
* <pre> | ||
* {@code | ||
* try { | ||
* Map<String, String> fields = new HashMap<String, String>(); | ||
* fields.put("age", "25); | ||
* fields.put("city", "Buenos Aires"); | ||
* authAPI.signUp("[email protected]", "myself", new char[]{'s','e','c','r','e','t'}, "db-connection", "1234567890") | ||
* .setCustomFields(fields) | ||
* .execute(); | ||
* } catch (Auth0Exception e) { | ||
* //Something happened | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* @see <a href="https://auth0.com/docs/api/authentication#signup">Signup API docs</a> | ||
* @param email the desired user's email. | ||
* @param username the desired user's username. | ||
* @param password the desired user's password. | ||
* @param connection the database connection where the user is going to be created. | ||
* @param phoneNumber the desired users's phone number. | ||
* @return a Request to configure and execute. | ||
*/ | ||
public SignUpRequest signUp(String email, String username, char[] password, String connection, String phoneNumber) { | ||
Asserts.assertNotNull(phoneNumber, "phone number"); | ||
|
||
SignUpRequest request = this.signUp(email, username, password, connection); | ||
request.addParameter(KEY_PHONE_NUMBER, phoneNumber); | ||
return request; | ||
} | ||
|
||
/** | ||
* Creates a sign up request with the given credentials and database connection. | ||
* "Requires Username" option must be turned on in the Connection's configuration first. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,6 +400,13 @@ public void shouldThrowOnUsernameSignUpWithNullConnection() { | |
"'connection' cannot be null!"); | ||
} | ||
|
||
@Test | ||
public void shouldThrowOnUsernameAndPhoneNumberSignUpWithNullPhoneNumber() { | ||
verifyThrows(IllegalArgumentException.class, | ||
() -> api.signUp("[email protected]", "me", new char[]{'p','4','5','5','w','0','r','d'}, "my-connection", null), | ||
"'phone number' cannot be null!"); | ||
} | ||
|
||
@Test | ||
public void shouldHaveNotStrongPasswordWithDetailedDescription() throws Exception { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
@@ -424,6 +431,34 @@ public void shouldHaveNotStrongPasswordWithShortDetailedDescription() throws Exc | |
assertThat(ex.getDescription(), is(expectedDescription)); | ||
} | ||
|
||
@Test | ||
public void shouldCreateSignUpRequestWithUsernameAndPhoneNumber() throws Exception { | ||
SignUpRequest request = api.signUp("[email protected]", "me", new char[]{'p','4','5','5','w','0','r','d'}, "db-connection", "1234567890"); | ||
assertThat(request, is(notNullValue())); | ||
|
||
server.jsonResponse(AUTH_SIGN_UP_USERNAME, 200); | ||
CreatedUser response = request.execute().getBody(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
assertThat(recordedRequest, hasMethodAndPath(HttpMethod.POST, "/dbconnections/signup")); | ||
assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); | ||
|
||
Map<String, Object> body = bodyFromRequest(recordedRequest); | ||
assertThat(body, hasEntry("email", "[email protected]")); | ||
assertThat(body, hasEntry("username", "me")); | ||
assertThat(body, hasEntry("password", "p455w0rd")); | ||
assertThat(body, hasEntry("connection", "db-connection")); | ||
assertThat(body, hasEntry("client_id", CLIENT_ID)); | ||
assertThat(body, hasEntry("phone_number", "1234567890")); | ||
|
||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getUserId(), is("58457fe6b27")); | ||
assertThat(response.getEmail(), is("[email protected]")); | ||
assertThat(response.isEmailVerified(), is(false)); | ||
assertThat(response.getUsername(), is("me")); | ||
assertThat(response.getPhoneNumber(), is("1234567890")); | ||
} | ||
|
||
@Test | ||
public void shouldCreateSignUpRequestWithUsername() throws Exception { | ||
@SuppressWarnings("deprecation") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
"_id": "58457fe6b27", | ||
"email_verified": false, | ||
"email": "[email protected]", | ||
"username": "me" | ||
} | ||
"username": "me", | ||
"phone_number": "1234567890" | ||
} |