2525package com .auth0 .authentication ;
2626
2727import com .auth0 .Auth0 ;
28+ import com .auth0 .authentication .result .Credentials ;
2829import com .auth0 .authentication .result .DatabaseUser ;
2930import com .auth0 .authentication .result .Delegation ;
30- import com .auth0 .authentication .result .Token ;
3131import com .auth0 .authentication .result .UserProfile ;
3232import com .auth0 .internal .RequestFactory ;
3333import com .auth0 .request .ParameterizableRequest ;
@@ -69,7 +69,6 @@ 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" ;
7372
7473 private final Auth0 auth0 ;
7574 private final OkHttpClient client ;
@@ -137,13 +136,13 @@ public void setDefaultDbConnection(String defaultDbConnection) {
137136 }
138137
139138 /**
140- * Log in a user with email/username and password using a DB connection and fetch it's profile from Auth0
139+ * Log in a user with email/username and password using a DB connection
141140 *
142141 * @param usernameOrEmail of the user depending of the type of DB connection
143142 * @param password of the user
144- * @return a request to configure and start that will yield {@link Token} and {@link UserProfile }
143+ * @return a request to configure and start that will yield {@link Credentials }
145144 */
146- public ParameterizableRequest <Token > login (String usernameOrEmail , String password ) {
145+ public ParameterizableRequest <Credentials > login (String usernameOrEmail , String password ) {
147146 Map <String , Object > requestParameters = ParameterBuilder .newAuthenticationBuilder ()
148147 .set (USERNAME_KEY , usernameOrEmail )
149148 .set (PASSWORD_KEY , password )
@@ -157,9 +156,9 @@ public ParameterizableRequest<Token> login(String usernameOrEmail, String passwo
157156 *
158157 * @param token obtained from the IdP
159158 * @param connection that will be used to authenticate the user, e.g. 'facebook'
160- * @return a request to configure and start that will yield {@link Token} and {@link UserProfile }
159+ * @return a request to configure and start that will yield {@link Credentials }
161160 */
162- public ParameterizableRequest <Token > loginWithOAuthAccessToken (String token , String connection ) {
161+ public ParameterizableRequest <Credentials > loginWithOAuthAccessToken (String token , String connection ) {
163162 HttpUrl url = HttpUrl .parse (auth0 .getDomainUrl ()).newBuilder ()
164163 .addPathSegment (OAUTH_PATH )
165164 .addPathSegment (ACCESS_TOKEN_PATH )
@@ -171,7 +170,7 @@ public ParameterizableRequest<Token> loginWithOAuthAccessToken(String token, Str
171170 .setAccessToken (token )
172171 .asDictionary ();
173172
174- ParameterizableRequest <Token > credentialsRequest = factory .POST (url , client , mapper , Token .class );
173+ ParameterizableRequest <Credentials > credentialsRequest = factory .POST (url , client , mapper , Credentials .class );
175174 credentialsRequest .getParameterBuilder ().addAll (parameters );
176175 return credentialsRequest ;
177176 }
@@ -181,9 +180,9 @@ public ParameterizableRequest<Token> loginWithOAuthAccessToken(String token, Str
181180 *
182181 * @param phoneNumber where the user received the verification code
183182 * @param verificationCode sent by Auth0 via SMS
184- * @return a request to configure and start that will yield {@link Token} and {@link UserProfile }
183+ * @return a request to configure and start that will yield {@link Credentials }
185184 */
186- public ParameterizableRequest <Token > loginWithPhoneNumber (String phoneNumber , String verificationCode ) {
185+ public ParameterizableRequest <Credentials > loginWithPhoneNumber (String phoneNumber , String verificationCode ) {
187186 Map <String , Object > parameters = ParameterBuilder .newAuthenticationBuilder ()
188187 .set (USERNAME_KEY , phoneNumber )
189188 .set (PASSWORD_KEY , verificationCode )
@@ -199,9 +198,9 @@ public ParameterizableRequest<Token> loginWithPhoneNumber(String phoneNumber, St
199198 *
200199 * @param email where the user received the verification code
201200 * @param verificationCode sent by Auth0 via Email
202- * @return a request to configure and start that will yield {@link Token} and {@link UserProfile }
201+ * @return a request to configure and start that will yield {@link Credentials }
203202 */
204- public ParameterizableRequest <Token > loginWithEmail (String email , String verificationCode ) {
203+ public ParameterizableRequest <Credentials > loginWithEmail (String email , String verificationCode ) {
205204 Map <String , Object > parameters = ParameterBuilder .newAuthenticationBuilder ()
206205 .set (USERNAME_KEY , email )
207206 .set (PASSWORD_KEY , verificationCode )
@@ -261,40 +260,40 @@ public ParameterizableRequest<DatabaseUser> createUser(String email, String pass
261260
262261 /**
263262 * Creates a user in a DB connection using <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-signup">'/dbconnections/signup' endpoint</a>
264- * and then logs in and fetches it's user profile
263+ * and then logs in
265264 *
266265 * @param email of the user and must be non null
267266 * @param password of the user and must be non null
268267 * @param username of the user and must be non null
269- * @return a request to configure and start that will yield {@link Token} and {@link UserProfile }
268+ * @return a request to configure and start that will yield {@link Credentials }
270269 */
271270 public SignUpRequest signUp (String email , String password , String username ) {
272271 final ParameterizableRequest <DatabaseUser > createUserRequest = createUser (email , password , username );
273- final ParameterizableRequest <Token > authenticationRequest = login (email , password );
272+ final ParameterizableRequest <Credentials > authenticationRequest = login (email , password );
274273 return new SignUpRequest (createUserRequest , authenticationRequest );
275274 }
276275
277276 /**
278277 * Creates a user in a DB connection using <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-signup">'/dbconnections/signup' endpoint</a>
279- * and then logs in and fetches it's user profile
278+ * and then logs in
280279 *
281280 * @param email of the user and must be non null
282281 * @param password of the user and must be non null
283- * @return a request to configure and start that will yield {@link Token} and {@link UserProfile }
282+ * @return a request to configure and start that will yield {@link Credentials }
284283 */
285284 public SignUpRequest signUp (String email , String password ) {
286285 ParameterizableRequest <DatabaseUser > createUserRequest = createUser (email , password );
287- final ParameterizableRequest <Token > authenticationRequest = login (email , password );
286+ final ParameterizableRequest <Credentials > authenticationRequest = login (email , password );
288287 return new SignUpRequest (createUserRequest , authenticationRequest );
289288 }
290289
291290 /**
292- * Perform a change password request using <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password">'/dbconnections/change_password'</a>
291+ * Request a change password using <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password">'/dbconnections/change_password'</a>
293292 *
294- * @param email of the user that changes the password. It's also where the confirmation email will be sent
293+ * @param email of the user that changes the password. It's also where the email will be sent with the link to perform the change password.
295294 * @return a request to configure and start
296295 */
297- public ChangePasswordRequest changePassword (String email ) {
296+ public ChangePasswordRequest requestChangePassword (String email ) {
298297 HttpUrl url = HttpUrl .parse (auth0 .getDomainUrl ()).newBuilder ()
299298 .addPathSegment (DB_CONNECTIONS_PATH )
300299 .addPathSegment (CHANGE_PASSWORD_PATH )
@@ -466,18 +465,24 @@ public ParameterizableRequest<Void> passwordless() {
466465 return request ;
467466 }
468467
469- public AuthenticationRequest getProfileAfter (ParameterizableRequest <Token > loginRequest ) {
468+ /**
469+ * Fetch the user's profile after it's authenticated by a login request.
470+ * If the login request fails, the returned request will fail
471+ * @param loginRequest that will authenticate a user with Auth0 and return a {@see Credentials}
472+ * @return a {@see AuthenticationRequest} that first logins and the fetches the profile
473+ */
474+ public AuthenticationRequest getProfileAfter (ParameterizableRequest <Credentials > loginRequest ) {
470475 final ParameterizableRequest <UserProfile > profileRequest = profileRequest ();
471476 return new AuthenticationRequest (loginRequest , profileRequest );
472477 }
473478
474- protected ParameterizableRequest <Token > loginWithResourceOwner (Map <String , Object > parameters ) {
479+ protected ParameterizableRequest <Credentials > loginWithResourceOwner (Map <String , Object > parameters ) {
475480 HttpUrl url = HttpUrl .parse (auth0 .getDomainUrl ()).newBuilder ()
476481 .addPathSegment (OAUTH_PATH )
477482 .addPathSegment (RESOURCE_OWNER_PATH )
478483 .build ();
479484
480- ParameterizableRequest <Token > request = factory .POST (url , client , mapper , Token .class );
485+ ParameterizableRequest <Credentials > request = factory .POST (url , client , mapper , Credentials .class );
481486 request .getParameterBuilder ()
482487 .setClientId (getClientId ())
483488 .setConnection (defaultDbConnection )
0 commit comments