@@ -69,6 +69,7 @@ public class AuthenticationAPIClient {
6969 private static final String OAUTH_PATH = "oauth" ;
7070 private static final String RESOURCE_OWNER_PATH = "ro" ;
7171 private static final String TOKEN_INFO_PATH = "tokeninfo" ;
72+ private static final String ID_TOKEN = "id_token" ;
7273
7374 private final Auth0 auth0 ;
7475 private final OkHttpClient client ;
@@ -142,13 +143,13 @@ public void setDefaultDbConnection(String defaultDbConnection) {
142143 * @param password of the user
143144 * @return a request to configure and start that will yield {@link Token} and {@link UserProfile}
144145 */
145- public AuthenticationRequest login (String usernameOrEmail , String password ) {
146+ public ParameterizableRequest < Token > login (String usernameOrEmail , String password ) {
146147 Map <String , Object > requestParameters = ParameterBuilder .newAuthenticationBuilder ()
147148 .set (USERNAME_KEY , usernameOrEmail )
148149 .set (PASSWORD_KEY , password )
149150 .setGrantType (GRANT_TYPE_PASSWORD )
150151 .asDictionary ();
151- return newAuthenticationRequest (requestParameters );
152+ return loginWithResourceOwner (requestParameters );
152153 }
153154
154155 /**
@@ -158,7 +159,7 @@ public AuthenticationRequest login(String usernameOrEmail, String password) {
158159 * @param connection that will be used to authenticate the user, e.g. 'facebook'
159160 * @return a request to configure and start that will yield {@link Token} and {@link UserProfile}
160161 */
161- public AuthenticationRequest loginWithOAuthAccessToken (String token , String connection ) {
162+ public ParameterizableRequest < Token > loginWithOAuthAccessToken (String token , String connection ) {
162163 HttpUrl url = HttpUrl .parse (auth0 .getDomainUrl ()).newBuilder ()
163164 .addPathSegment (OAUTH_PATH )
164165 .addPathSegment (ACCESS_TOKEN_PATH )
@@ -170,10 +171,9 @@ public AuthenticationRequest loginWithOAuthAccessToken(String token, String conn
170171 .setAccessToken (token )
171172 .asDictionary ();
172173
173- final ParameterizableRequest <UserProfile > profileRequest = profileRequest ();
174174 ParameterizableRequest <Token > credentialsRequest = factory .POST (url , client , mapper , Token .class );
175175 credentialsRequest .getParameterBuilder ().addAll (parameters );
176- return new AuthenticationRequest ( credentialsRequest , profileRequest ) ;
176+ return credentialsRequest ;
177177 }
178178
179179 /**
@@ -183,15 +183,15 @@ public AuthenticationRequest loginWithOAuthAccessToken(String token, String conn
183183 * @param verificationCode sent by Auth0 via SMS
184184 * @return a request to configure and start that will yield {@link Token} and {@link UserProfile}
185185 */
186- public AuthenticationRequest loginWithPhoneNumber (String phoneNumber , String verificationCode ) {
186+ public ParameterizableRequest < Token > loginWithPhoneNumber (String phoneNumber , String verificationCode ) {
187187 Map <String , Object > parameters = ParameterBuilder .newAuthenticationBuilder ()
188188 .set (USERNAME_KEY , phoneNumber )
189189 .set (PASSWORD_KEY , verificationCode )
190190 .setGrantType (GRANT_TYPE_PASSWORD )
191191 .setClientId (getClientId ())
192192 .setConnection (SMS_CONNECTION )
193193 .asDictionary ();
194- return newAuthenticationRequest (parameters );
194+ return loginWithResourceOwner (parameters );
195195 }
196196
197197 /**
@@ -201,15 +201,15 @@ public AuthenticationRequest loginWithPhoneNumber(String phoneNumber, String ver
201201 * @param verificationCode sent by Auth0 via Email
202202 * @return a request to configure and start that will yield {@link Token} and {@link UserProfile}
203203 */
204- public AuthenticationRequest loginWithEmail (String email , String verificationCode ) {
204+ public ParameterizableRequest < Token > loginWithEmail (String email , String verificationCode ) {
205205 Map <String , Object > parameters = ParameterBuilder .newAuthenticationBuilder ()
206206 .set (USERNAME_KEY , email )
207207 .set (PASSWORD_KEY , verificationCode )
208208 .setGrantType (GRANT_TYPE_PASSWORD )
209209 .setClientId (getClientId ())
210210 .setConnection (EMAIL_CONNECTION )
211211 .asDictionary ();
212- return newAuthenticationRequest (parameters );
212+ return loginWithResourceOwner (parameters );
213213 }
214214
215215 /**
@@ -269,8 +269,8 @@ public ParameterizableRequest<DatabaseUser> createUser(String email, String pass
269269 * @return a request to configure and start that will yield {@link Token} and {@link UserProfile}
270270 */
271271 public SignUpRequest signUp (String email , String password , String username ) {
272- ParameterizableRequest <DatabaseUser > createUserRequest = createUser (email , password , username );
273- AuthenticationRequest authenticationRequest = login (email , password );
272+ final ParameterizableRequest <DatabaseUser > createUserRequest = createUser (email , password , username );
273+ final ParameterizableRequest < Token > authenticationRequest = login (email , password );
274274 return new SignUpRequest (createUserRequest , authenticationRequest );
275275 }
276276
@@ -284,7 +284,7 @@ public SignUpRequest signUp(String email, String password, String username) {
284284 */
285285 public SignUpRequest signUp (String email , String password ) {
286286 ParameterizableRequest <DatabaseUser > createUserRequest = createUser (email , password );
287- AuthenticationRequest authenticationRequest = login (email , password );
287+ final ParameterizableRequest < Token > authenticationRequest = login (email , password );
288288 return new SignUpRequest (createUserRequest , authenticationRequest );
289289 }
290290
@@ -466,7 +466,12 @@ public ParameterizableRequest<Void> passwordless() {
466466 return request ;
467467 }
468468
469- protected ParameterizableRequest <Token > loginWithResourceOwner () {
469+ public AuthenticationRequest getProfileAfter (ParameterizableRequest <Token > loginRequest ) {
470+ final ParameterizableRequest <UserProfile > profileRequest = profileRequest ();
471+ return new AuthenticationRequest (loginRequest , profileRequest );
472+ }
473+
474+ protected ParameterizableRequest <Token > loginWithResourceOwner (Map <String , Object > parameters ) {
470475 HttpUrl url = HttpUrl .parse (auth0 .getDomainUrl ()).newBuilder ()
471476 .addPathSegment (OAUTH_PATH )
472477 .addPathSegment (RESOURCE_OWNER_PATH )
@@ -475,7 +480,8 @@ protected ParameterizableRequest<Token> loginWithResourceOwner() {
475480 ParameterizableRequest <Token > request = factory .POST (url , client , mapper , Token .class );
476481 request .getParameterBuilder ()
477482 .setClientId (getClientId ())
478- .setConnection (defaultDbConnection );
483+ .setConnection (defaultDbConnection )
484+ .addAll (parameters );
479485 return request ;
480486 }
481487
@@ -486,12 +492,4 @@ private ParameterizableRequest<UserProfile> profileRequest() {
486492
487493 return factory .POST (url , client , mapper , UserProfile .class );
488494 }
489-
490- private AuthenticationRequest newAuthenticationRequest (Map <String , Object > parameters ) {
491- final ParameterizableRequest <Token > credentialsRequest = loginWithResourceOwner ();
492- final ParameterizableRequest <UserProfile > profileRequest = profileRequest ();
493-
494- return new AuthenticationRequest (credentialsRequest , profileRequest )
495- .addParameters (parameters );
496- }
497495}
0 commit comments