/** * Log in a user with email/username and password using a DB connection. Example usage: * * <pre><code> * client.login("{username or email}", "{password}") * .setConnection("{database connection name}") * .start(new BaseCallback<Credentials>() { * {@literal}Override * public void onSuccess(Credentials payload) { } * * {@literal}Override * public void onFailure(Auth0Exception error) { } * }); * </code></pre> * * @param usernameOrEmail of the user depending of the type of DB connection * @param password of the user * @return a request to configure and start that will yield {@link Credentials} */ @SuppressWarnings("WeakerAccess") public AuthenticationRequest login(String usernameOrEmail, String password) { Map<String, Object> requestParameters = ParameterBuilder.newAuthenticationBuilder() .set(USERNAME_KEY, usernameOrEmail) .set(PASSWORD_KEY, password) .setGrantType(GRANT_TYPE_PASSWORD) .asDictionary(); return loginWithResourceOwner(requestParameters); }
/** * Log in a user using an email and a verification code received via Email (Part of passwordless * login flow) Example usage: * * <pre><code> * client.loginWithEmail("{email}", "{code}") * .start(new BaseCallback<Credentials>() { * {@literal}Override * public void onSuccess(Credentials payload) { } * * {@literal}@Override * public void onFailure(Auth0Exception error) { } * }); * </code></pre> * * @param email where the user received the verification code * @param verificationCode sent by Auth0 via Email * @return a request to configure and start that will yield {@link Credentials} */ @SuppressWarnings("WeakerAccess") public AuthenticationRequest loginWithEmail(String email, String verificationCode) { Map<String, Object> parameters = ParameterBuilder.newAuthenticationBuilder() .set(USERNAME_KEY, email) .set(PASSWORD_KEY, verificationCode) .setGrantType(GRANT_TYPE_PASSWORD) .setClientId(getClientId()) .setConnection(EMAIL_CONNECTION) .asDictionary(); return loginWithResourceOwner(parameters); }
/** * Log in a user with a OAuth 'access_token' of a Identity Provider like Facebook or Twitter using * <a href="https://auth0.com/docs/auth-api#!#post--oauth-access_token">'\oauth\access_token' * endpoint</a> Example usage: * * <pre><code> * client.loginWithOAuthAccessToken("{token}", "{connection name}") * .setConnection("second-database") * .start(new BaseCallback<Credentials>() { * {@literal}Override * public void onSuccess(Credentials payload) { } * * {@literal}Override * public void onFailure(Auth0Exception error) { } * }); * </code></pre> * * @param token obtained from the IdP * @param connection that will be used to authenticate the user, e.g. 'facebook' * @return a request to configure and start that will yield {@link Credentials} */ @SuppressWarnings("WeakerAccess") public AuthenticationRequest loginWithOAuthAccessToken(String token, String connection) { HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()) .newBuilder() .addPathSegment(OAUTH_PATH) .addPathSegment(ACCESS_TOKEN_PATH) .build(); Map<String, Object> parameters = ParameterBuilder.newAuthenticationBuilder() .setClientId(getClientId()) .setConnection(connection) .setAccessToken(token) .asDictionary(); return factory.authenticationPOST(url, client, gson).addAuthenticationParameters(parameters); }