Skip to content

Commit

Permalink
feat. log in with us/pw using the /oauth/token endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Nov 24, 2016
1 parent eca69f4 commit 14d8a38
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <pre><code>
Expand Down Expand Up @@ -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:
* <pre><code>
* client.loginWithToken("{username or email}", "{password}")
* .start(new BaseCallback<Credentials>() {
* {@literal}Override
* public void onSuccess(Credentials payload) { }
*
* {@literal}Override
* public void onFailure(AuthenticationException error) { }
* });
* </code></pre>
*
* @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<String, Object> 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 <a href="https://auth0.com/docs/auth-api#!#post--oauth-access_token">'\oauth\access_token' endpoint</a>
* The default scope used is 'openid'.
Expand Down Expand Up @@ -817,6 +846,20 @@ public TokenRequest token(@NonNull String authorizationCode, @NonNull String red
return new TokenRequest(request);
}

private AuthenticationRequest loginWithToken(Map<String, Object> parameters) {
HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
.addPathSegment(OAUTH_PATH)
.addPathSegment(TOKEN_PATH)
.build();

final Map<String, Object> requestParameters = ParameterBuilder.newBuilder()
.setClientId(getClientId())
.addAll(parameters)
.asDictionary();
return factory.authenticationPOST(url, client, gson)
.addAuthenticationParameters(requestParameters);
}

private AuthenticationRequest loginWithResourceOwner(Map<String, Object> parameters) {
HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
.addPathSegment(OAUTH_PATH)
Expand Down

0 comments on commit 14d8a38

Please sign in to comment.