-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include a proper SignUp response #92
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -121,7 +121,7 @@ fields.put("city", "Buenos Aires"); | |
SignUpRequest request = auth.signUp("[email protected]", "username", "password123", "Username-Password-Authentication") | ||
.setCustomFields(fields); | ||
try { | ||
request.execute(); | ||
CreatedUser user = request.execute(); | ||
} catch (APIException exception) { | ||
// api error | ||
} catch (Auth0Exception exception) { | ||
|
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.auth0.json.auth; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Class that holds the data of a newly created User. Obtained after a call to {@link com.auth0.client.auth.AuthAPI#signUp(String, String, String)} | ||
* or {@link com.auth0.client.auth.AuthAPI#signUp(String, String, String, String)}. | ||
*/ | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class CreatedUser { | ||
|
||
@JsonProperty("_id") | ||
private String userId; | ||
@JsonProperty("email") | ||
private String email; | ||
@JsonProperty("username") | ||
private String username; | ||
@JsonProperty("email_verified") | ||
private Boolean emailVerified; | ||
|
||
@JsonProperty("_id") | ||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
@JsonProperty("email") | ||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
@JsonProperty("username") | ||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
@JsonProperty("email_verified") | ||
public Boolean isEmailVerified() { | ||
return emailVerified; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.auth0.net; | ||
|
||
import com.auth0.json.auth.CreatedUser; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.OkHttpClient; | ||
|
||
import java.util.Map; | ||
|
||
public class CreateUserRequest extends CustomRequest<CreatedUser> implements SignUpRequest { | ||
|
||
public CreateUserRequest(OkHttpClient client, String url) { | ||
super(client, url, "POST", new TypeReference<CreatedUser>() { | ||
}); | ||
} | ||
|
||
@Override | ||
public SignUpRequest setCustomFields(Map<String, String> customFields) { | ||
super.addParameter("user_metadata", customFields); | ||
return this; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.auth0.client.auth; | ||
|
||
import com.auth0.client.MockServer; | ||
import com.auth0.json.auth.CreatedUser; | ||
import com.auth0.json.auth.TokenHolder; | ||
import com.auth0.json.auth.UserInfo; | ||
import com.auth0.net.AuthRequest; | ||
|
@@ -383,8 +384,8 @@ public void shouldCreateSignUpRequestWithUsername() throws Exception { | |
SignUpRequest request = api.signUp("[email protected]", "me", "p455w0rd", "db-connection"); | ||
assertThat(request, is(notNullValue())); | ||
|
||
server.jsonResponse(AUTH_SIGN_UP, 200); | ||
Void response = request.execute(); | ||
server.jsonResponse(AUTH_SIGN_UP_USERNAME, 200); | ||
CreatedUser response = request.execute(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
assertThat(recordedRequest, hasMethodAndPath("POST", "/dbconnections/signup")); | ||
|
@@ -397,7 +398,11 @@ public void shouldCreateSignUpRequestWithUsername() throws Exception { | |
assertThat(body, hasEntry("connection", (Object) "db-connection")); | ||
assertThat(body, hasEntry("client_id", (Object) CLIENT_ID)); | ||
|
||
assertThat(response, is(nullValue())); | ||
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")); | ||
} | ||
|
||
@Test | ||
|
@@ -406,7 +411,7 @@ public void shouldCreateSignUpRequest() throws Exception { | |
assertThat(request, is(notNullValue())); | ||
|
||
server.jsonResponse(AUTH_SIGN_UP, 200); | ||
Void response = request.execute(); | ||
CreatedUser response = request.execute(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
assertThat(recordedRequest, hasMethodAndPath("POST", "/dbconnections/signup")); | ||
|
@@ -419,7 +424,11 @@ public void shouldCreateSignUpRequest() throws Exception { | |
assertThat(body, hasEntry("client_id", (Object) CLIENT_ID)); | ||
assertThat(body, not(hasKey("username"))); | ||
|
||
assertThat(response, is(nullValue())); | ||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getUserId(), is("58457fe6b27")); | ||
assertThat(response.getEmail(), is("[email protected]")); | ||
assertThat(response.isEmailVerified(), is(false)); | ||
assertThat(response.getUsername(), is(nullValue())); | ||
} | ||
|
||
@Test | ||
|
@@ -432,7 +441,7 @@ public void shouldCreateSignUpRequestWithCustomParameters() throws Exception { | |
request.setCustomFields(customFields); | ||
|
||
server.jsonResponse(AUTH_SIGN_UP, 200); | ||
Void response = request.execute(); | ||
CreatedUser response = request.execute(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
assertThat(recordedRequest, hasMethodAndPath("POST", "/dbconnections/signup")); | ||
|
@@ -449,7 +458,11 @@ public void shouldCreateSignUpRequestWithCustomParameters() throws Exception { | |
assertThat(metadata, hasEntry("address", "123, fake street")); | ||
assertThat(body, not(hasKey("username"))); | ||
|
||
assertThat(response, is(nullValue())); | ||
assertThat(response, is(notNullValue())); | ||
assertThat(response.getUserId(), is("58457fe6b27")); | ||
assertThat(response.getEmail(), is("[email protected]")); | ||
assertThat(response.isEmailVerified(), is(false)); | ||
assertThat(response.getUsername(), is(nullValue())); | ||
} | ||
|
||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.auth0.net; | ||
|
||
import com.auth0.client.MockServer; | ||
import com.auth0.json.auth.CreatedUser; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.auth0.client.MockServer.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class CreateUserRequestTest { | ||
|
||
private OkHttpClient client; | ||
private MockServer server; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
client = new OkHttpClient(); | ||
server = new MockServer(); | ||
} | ||
|
||
@Test | ||
public void shouldCreatePOSTRequest() throws Exception { | ||
CreateUserRequest request = new CreateUserRequest(client, server.getBaseUrl()); | ||
assertThat(request, is(notNullValue())); | ||
request.addParameter("non_empty", "body"); | ||
|
||
server.jsonResponse(AUTH_SIGN_UP, 200); | ||
CreatedUser execute = request.execute(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
assertThat(recordedRequest.getMethod(), is("POST")); | ||
assertThat(execute, is(notNullValue())); | ||
} | ||
|
||
@Test | ||
public void shouldSetSignUpCustomFields() throws Exception { | ||
CreateUserRequest request = new CreateUserRequest(client, server.getBaseUrl()); | ||
assertThat(request, is(notNullValue())); | ||
Map<String, String> customFields = new HashMap<>(); | ||
customFields.put("name", "john"); | ||
customFields.put("age", "25"); | ||
request.setCustomFields(customFields); | ||
|
||
server.jsonResponse(AUTH_TOKENS, 200); | ||
request.execute(); | ||
RecordedRequest recordedRequest = server.takeRequest(); | ||
|
||
Map<String, Object> values = bodyFromRequest(recordedRequest); | ||
assertThat(values, is(notNullValue())); | ||
assertThat(values, hasKey("user_metadata")); | ||
Map<String, String> fields = (Map<String, String>) values.get("user_metadata"); | ||
assertThat(fields, hasEntry("name", "john")); | ||
assertThat(fields, hasEntry("age", "25")); | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"_id": "58457fe6b27...", | ||
"_id": "58457fe6b27", | ||
"email_verified": false, | ||
"email": "test.account@signup.com" | ||
"email": "me@auth0.com" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"_id": "58457fe6b27", | ||
"email_verified": false, | ||
"email": "[email protected]", | ||
"username": "me" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a BC as Public API removal, this is a compile fail for anyone using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"CustomFields" were supposed to be available only for SignUp methods. Because of how the request classes were inherited, this method ended wrongly in the
VoidRequest
class. No, it wouldn't be a breaking change as there's not a single API method signature that declares a return type of VoidRequest. They all either return anAuthRequest
(never aTokenRequest
),SignUpRequest
(never aCreateUserRequest
) or a simpleRequest
orRequest<T>
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people were casting that returned type to
VoidRequest
(in the case that that method call was returning aVoidRequest
class or subclass) and using that method, then yes it would be a breaking change. But that's why we return interfaces rather than classes, to obscure our internals. So I wouldn't consider this a breaking change anyway.