Skip to content

Commit 3625468

Browse files
committed
Rename Token to Credentials
1 parent 97e4a98 commit 3625468

9 files changed

Lines changed: 117 additions & 110 deletions

File tree

lib/src/main/java/com/auth0/authentication/AuthenticationAPIClient.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
package com.auth0.authentication;
2626

2727
import com.auth0.Auth0;
28+
import com.auth0.authentication.result.Credentials;
2829
import com.auth0.authentication.result.DatabaseUser;
2930
import com.auth0.authentication.result.Delegation;
30-
import com.auth0.authentication.result.Token;
3131
import com.auth0.authentication.result.UserProfile;
3232
import com.auth0.internal.RequestFactory;
3333
import 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)

lib/src/main/java/com/auth0/authentication/AuthenticationRequest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
package com.auth0.authentication;
2626

2727
import com.auth0.Auth0Exception;
28+
import com.auth0.authentication.result.Credentials;
2829
import com.auth0.request.ParameterizableRequest;
2930
import com.auth0.request.Request;
3031
import com.auth0.callback.BaseCallback;
31-
import com.auth0.authentication.result.Token;
3232
import com.auth0.authentication.result.UserProfile;
3333
import com.auth0.authentication.result.Authentication;
3434

@@ -41,10 +41,10 @@ public class AuthenticationRequest implements Request<Authentication> {
4141

4242
private static final String ID_TOKEN_KEY = "id_token";
4343

44-
private final ParameterizableRequest<Token> credentialsRequest;
44+
private final ParameterizableRequest<Credentials> credentialsRequest;
4545
private final ParameterizableRequest<UserProfile> tokenInfoRequest;
4646

47-
AuthenticationRequest(ParameterizableRequest<Token> credentialsRequest, ParameterizableRequest<UserProfile> tokenInfoRequest) {
47+
AuthenticationRequest(ParameterizableRequest<Credentials> credentialsRequest, ParameterizableRequest<UserProfile> tokenInfoRequest) {
4848
this.credentialsRequest = credentialsRequest;
4949
this.tokenInfoRequest = tokenInfoRequest;
5050
}
@@ -89,17 +89,17 @@ public AuthenticationRequest setConnection(String connection) {
8989
*/
9090
@Override
9191
public void start(final BaseCallback<Authentication> callback) {
92-
credentialsRequest.start(new BaseCallback<Token>() {
92+
credentialsRequest.start(new BaseCallback<Credentials>() {
9393
@Override
94-
public void onSuccess(final Token token) {
94+
public void onSuccess(final Credentials credentials) {
9595
tokenInfoRequest
9696
.getParameterBuilder()
97-
.set(ID_TOKEN_KEY, token.getIdToken());
97+
.set(ID_TOKEN_KEY, credentials.getIdToken());
9898
tokenInfoRequest
9999
.start(new BaseCallback<UserProfile>() {
100100
@Override
101101
public void onSuccess(UserProfile profile) {
102-
callback.onSuccess(new Authentication(profile, token));
102+
callback.onSuccess(new Authentication(profile, credentials));
103103
}
104104

105105
@Override
@@ -124,10 +124,10 @@ public void onFailure(Auth0Exception error) {
124124
*/
125125
@Override
126126
public Authentication execute() throws Auth0Exception {
127-
Token token = credentialsRequest.execute();
128-
tokenInfoRequest.getParameterBuilder().set(ID_TOKEN_KEY, token.getIdToken());
127+
Credentials credentials = credentialsRequest.execute();
128+
tokenInfoRequest.getParameterBuilder().set(ID_TOKEN_KEY, credentials.getIdToken());
129129
UserProfile profile = tokenInfoRequest
130130
.execute();
131-
return new Authentication(profile, token);
131+
return new Authentication(profile, credentials);
132132
}
133133
}

lib/src/main/java/com/auth0/authentication/SignUpRequest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,23 @@
2525
package com.auth0.authentication;
2626

2727
import com.auth0.Auth0Exception;
28-
import com.auth0.authentication.result.Token;
28+
import com.auth0.authentication.result.Credentials;
2929
import com.auth0.request.ParameterizableRequest;
3030
import com.auth0.request.Request;
3131
import com.auth0.callback.BaseCallback;
3232
import com.auth0.authentication.result.DatabaseUser;
33-
import com.auth0.authentication.result.Authentication;
3433

3534
import java.util.Map;
3635

3736
/**
3837
* Represent a request to create a user + log in
3938
*/
40-
public class SignUpRequest implements Request<Token> {
39+
public class SignUpRequest implements Request<Credentials> {
4140

4241
private final ParameterizableRequest<DatabaseUser> signUpRequest;
43-
private final ParameterizableRequest<Token> authenticationRequest;
42+
private final ParameterizableRequest<Credentials> authenticationRequest;
4443

45-
SignUpRequest(ParameterizableRequest<DatabaseUser> signUpRequest, ParameterizableRequest<Token> authenticationRequest) {
44+
SignUpRequest(ParameterizableRequest<DatabaseUser> signUpRequest, ParameterizableRequest<Credentials> authenticationRequest) {
4645
this.signUpRequest = signUpRequest;
4746
this.authenticationRequest = authenticationRequest;
4847
}
@@ -98,7 +97,7 @@ public SignUpRequest setConnection(String connection) {
9897
* @param callback called on either success or failure.
9998
*/
10099
@Override
101-
public void start(final BaseCallback<Token> callback) {
100+
public void start(final BaseCallback<Credentials> callback) {
102101
signUpRequest.start(new BaseCallback<DatabaseUser>() {
103102
@Override
104103
public void onSuccess(final DatabaseUser user) {
@@ -119,7 +118,7 @@ public void onFailure(Auth0Exception error) {
119118
* @throws Auth0Exception on failure
120119
*/
121120
@Override
122-
public Token execute() throws Auth0Exception {
121+
public Credentials execute() throws Auth0Exception {
123122
signUpRequest.execute();
124123
return authenticationRequest.execute();
125124
}

lib/src/main/java/com/auth0/authentication/result/Authentication.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,26 @@
2929

3030
/**
3131
* The result of a successful authentication against Auth0
32-
* Contains the logged in user's {@link Token} and {@link UserProfile}
32+
* Contains the logged in user's {@link Credentials} and {@link UserProfile}.
33+
* @see com.auth0.authentication.AuthenticationAPIClient#getProfileAfter(com.auth0.request.ParameterizableRequest)
3334
*/
3435
public class Authentication {
3536

3637
private final UserProfile profile;
37-
private final Token token;
38+
private final Credentials credentials;
3839

39-
public Authentication(UserProfile profile, Token token) {
40+
public Authentication(UserProfile profile, Credentials credentials) {
4041
checkArgument(profile != null, "profile must be non-null");
41-
checkArgument(token != null, "token must be non-null");
42+
checkArgument(credentials != null, "credentials must be non-null");
4243
this.profile = profile;
43-
this.token = token;
44+
this.credentials = credentials;
4445
}
4546

4647
public UserProfile getProfile() {
4748
return profile;
4849
}
4950

50-
public Token getToken() {
51-
return token;
51+
public Credentials getCredentials() {
52+
return credentials;
5253
}
5354
}

lib/src/main/java/com/auth0/authentication/result/Token.java renamed to lib/src/main/java/com/auth0/authentication/result/Credentials.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,34 @@
2828
import com.fasterxml.jackson.annotation.JsonProperty;
2929

3030
/**
31-
* Class that holds a user's token information.
31+
* Holds the user's credentials returned by Auth0.
32+
* <ul>
33+
* <li><i>idToken</i>: Identity Token with user information</li>
34+
* <li><i>accessToken</i>: Access Token for Auth0 API</li>
35+
* <li><i>refreshToken</i>: Refresh Token that can be used to request new tokens without signing in again</li>
36+
* </ul>
3237
*/
3338
@JsonIgnoreProperties(ignoreUnknown = true)
34-
public class Token {
39+
public class Credentials {
3540

3641
protected String idToken;
3742
protected String accessToken;
3843
protected String type;
3944
protected String refreshToken;
4045

41-
protected Token(Token token) {
42-
idToken = token.idToken;
43-
accessToken = token.accessToken;
44-
type = token.type;
45-
refreshToken = token.refreshToken;
46+
protected Credentials(Credentials credentials) {
47+
idToken = credentials.idToken;
48+
accessToken = credentials.accessToken;
49+
type = credentials.type;
50+
refreshToken = credentials.refreshToken;
4651
}
4752

48-
protected Token() {
53+
protected Credentials() { }
4954

50-
}
51-
52-
public Token(@JsonProperty(value = "id_token", required = true) String idToken,
53-
@JsonProperty(value = "access_token") String accessToken,
54-
@JsonProperty(value = "token_type") String type,
55-
@JsonProperty(value = "refresh_token") String refreshToken) {
55+
public Credentials(@JsonProperty(value = "id_token", required = true) String idToken,
56+
@JsonProperty(value = "access_token") String accessToken,
57+
@JsonProperty(value = "token_type") String type,
58+
@JsonProperty(value = "refresh_token") String refreshToken) {
5659
this.idToken = idToken;
5760
this.accessToken = accessToken;
5861
this.type = type;

lib/src/main/java/com/auth0/authentication/result/DatabaseUser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import com.fasterxml.jackson.annotation.JsonProperty;
2929

3030
/**
31-
* Value holder for Database Sign Up operation
31+
* Auth0 user created in a Database connection.
32+
*
33+
* @see com.auth0.authentication.AuthenticationAPIClient#signUp(String, String)
34+
* @see com.auth0.authentication.AuthenticationAPIClient#signUp(String, String, String)
3235
*/
3336
@JsonIgnoreProperties(ignoreUnknown = true)
3437
public class DatabaseUser {

lib/src/main/java/com/auth0/authentication/result/Delegation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import static com.auth0.util.CheckHelper.checkArgument;
3232

3333
/**
34-
* The result of a successful delegation to an Auth0 app.
35-
* Contains a new Auth0 'id_token' to be used on the 'target' app
34+
* The result of a successful delegation to an Auth0 application that contains a new Auth0 'id_token'
3635
* See <a href="https://auth0.com/docs/auth-api#!#post--delegation">delegation</a> docs
3736
*/
3837
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -54,7 +53,7 @@ public Delegation(@JsonProperty(value = "id_token") String idToken,
5453
}
5554

5655
/**
57-
* Id token
56+
* Identity Token
5857
* @return the 'id_token' value
5958
*/
6059
public String getIdToken() {

0 commit comments

Comments
 (0)