diff --git a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java index 45a04598d..a5eeb26f1 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java +++ b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.java @@ -148,7 +148,7 @@ public void setUserAgent(String userAgent) { } /** - * Log in a user with email/username and password using a DB connection. + * Log in a user with email/username and password using a DB connection and the /oauth/ro endpoint. * The default scope used is 'openid'. * Example usage: *
@@ -178,6 +178,35 @@ public AuthenticationRequest login(@NonNull String usernameOrEmail, @NonNull Str
return loginWithResourceOwner(requestParameters);
}
+ /**
+ * Log in a user with email/username and password using the /oauth/token endpoint.
+ * Example usage:
+ *
+ * client.loginWithToken("{username or email}", "{password}")
+ * .start(new BaseCallback() {
+ * {@literal}Override
+ * public void onSuccess(Credentials payload) { }
+ *
+ * {@literal}Override
+ * public void onFailure(AuthenticationException error) { }
+ * });
+ *
+ *
+ * @param usernameOrEmail of the user
+ * @param password of the user
+ * @return a request to configure and start that will yield {@link Credentials}
+ */
+ @SuppressWarnings("WeakerAccess")
+ public AuthenticationRequest loginWithToken(@NonNull String usernameOrEmail, @NonNull String password) {
+ Map requestParameters = ParameterBuilder.newBuilder()
+ .set(USERNAME_KEY, usernameOrEmail)
+ .set(PASSWORD_KEY, password)
+ .setGrantType(GRANT_TYPE_PASSWORD)
+ .asDictionary();
+
+ return loginWithToken(requestParameters);
+ }
+
/**
* Log in a user with a OAuth 'access_token' of a Identity Provider like Facebook or Twitter using '\oauth\access_token' endpoint
* The default scope used is 'openid'.
@@ -817,6 +846,20 @@ public TokenRequest token(@NonNull String authorizationCode, @NonNull String red
return new TokenRequest(request);
}
+ private AuthenticationRequest loginWithToken(Map parameters) {
+ HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
+ .addPathSegment(OAUTH_PATH)
+ .addPathSegment(TOKEN_PATH)
+ .build();
+
+ final Map requestParameters = ParameterBuilder.newBuilder()
+ .setClientId(getClientId())
+ .addAll(parameters)
+ .asDictionary();
+ return factory.authenticationPOST(url, client, gson)
+ .addAuthenticationParameters(requestParameters);
+ }
+
private AuthenticationRequest loginWithResourceOwner(Map parameters) {
HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
.addPathSegment(OAUTH_PATH)