diff --git a/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.java b/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.java index de202be66..2d3f732b3 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.java +++ b/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.java @@ -63,6 +63,7 @@ public class ParameterBuilder { public static final String CLIENT_ID_KEY = "client_id"; public static final String GRANT_TYPE_KEY = "grant_type"; public static final String DEVICE_KEY = "device"; + public static final String AUDIENCE_KEY = "audience"; private Map parameters; @@ -111,6 +112,16 @@ public ParameterBuilder setScope(String scope) { return set(SCOPE_KEY, scope); } + /** + * Sets the 'audience' parameter. + * + * @param audience an audience value + * @return itself + */ + public ParameterBuilder setAudience(String audience) { + return set(AUDIENCE_KEY, audience); + } + /** * Sets the 'device' parameter * diff --git a/auth0/src/main/java/com/auth0/android/authentication/request/SignUpRequest.java b/auth0/src/main/java/com/auth0/android/authentication/request/SignUpRequest.java index 56a92267f..fae71c2f6 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/request/SignUpRequest.java +++ b/auth0/src/main/java/com/auth0/android/authentication/request/SignUpRequest.java @@ -88,6 +88,12 @@ public AuthenticationRequest setDevice(String device) { return this; } + @Override + public AuthenticationRequest setAudience(String audience) { + authenticationRequest.setAudience(audience); + return this; + } + @Override public AuthenticationRequest setAccessToken(String accessToken) { authenticationRequest.setAccessToken(accessToken); diff --git a/auth0/src/main/java/com/auth0/android/request/AuthenticationRequest.java b/auth0/src/main/java/com/auth0/android/request/AuthenticationRequest.java index 9271ff48d..0863abfb9 100755 --- a/auth0/src/main/java/com/auth0/android/request/AuthenticationRequest.java +++ b/auth0/src/main/java/com/auth0/android/request/AuthenticationRequest.java @@ -42,6 +42,14 @@ public interface AuthenticationRequest extends Request callback = new MockAuthenticationCallback<>(); + + client.loginWithToken(SUPPORT_AUTH0_COM, "some-password") + .start(callback); + assertThat(callback, hasPayloadOfType(Credentials.class)); + + final RecordedRequest request = mockAPI.takeRequest(); + assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale())); + Map body = bodyFromRequest(request); + assertThat(body, hasEntry("client_id", CLIENT_ID)); + assertThat(body, hasEntry("grant_type", "password")); + assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM)); + assertThat(body, hasEntry("password", "some-password")); + assertThat(body, not(hasKey("scope"))); + assertThat(body, not(hasKey("audience"))); + } + + @Test + public void shouldLoginWithUserAndPasswordSyncUsingOAuthTokenEndpoint() throws Exception { + mockAPI.willReturnSuccessfulLogin(); + + final Credentials credentials = client + .loginWithToken(SUPPORT_AUTH0_COM, "some-password") + .execute(); + assertThat(credentials, is(notNullValue())); + + final RecordedRequest request = mockAPI.takeRequest(); + assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale())); + Map body = bodyFromRequest(request); + assertThat(body, hasEntry("client_id", CLIENT_ID)); + assertThat(body, hasEntry("grant_type", "password")); + assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM)); + assertThat(body, hasEntry("password", "some-password")); + assertThat(body, not(hasKey("scope"))); + assertThat(body, not(hasKey("audience"))); + } + @Test public void shouldFetchTokenInfo() throws Exception { mockAPI.willReturnTokenInfo(); diff --git a/auth0/src/test/java/com/auth0/android/authentication/ParameterBuilderTest.java b/auth0/src/test/java/com/auth0/android/authentication/ParameterBuilderTest.java index d7b90fc29..485e29be3 100755 --- a/auth0/src/test/java/com/auth0/android/authentication/ParameterBuilderTest.java +++ b/auth0/src/test/java/com/auth0/android/authentication/ParameterBuilderTest.java @@ -92,6 +92,12 @@ public void shouldSetScope() throws Exception { assertThat(parameters, hasEntry("scope", ParameterBuilder.SCOPE_OFFLINE_ACCESS)); } + @Test + public void shouldSetAudience() throws Exception { + Map parameters = builder.setAudience("https://domain.auth0.com/api").asDictionary(); + assertThat(parameters, hasEntry("audience", "https://domain.auth0.com/api")); + } + @Test public void shouldSetDevice() throws Exception { Map parameters = builder.setDevice(DEVICE).asDictionary(); diff --git a/auth0/src/test/java/com/auth0/android/authentication/request/AuthenticationRequestMock.java b/auth0/src/test/java/com/auth0/android/authentication/request/AuthenticationRequestMock.java index 5fab9c509..8fae248b3 100644 --- a/auth0/src/test/java/com/auth0/android/authentication/request/AuthenticationRequestMock.java +++ b/auth0/src/test/java/com/auth0/android/authentication/request/AuthenticationRequestMock.java @@ -53,6 +53,11 @@ public AuthenticationRequest setDevice(String device) { return this; } + @Override + public AuthenticationRequest setAudience(String audience) { + return this; + } + @Override public AuthenticationRequest setAccessToken(String accessToken) { return this; diff --git a/auth0/src/test/java/com/auth0/android/authentication/request/SignUpRequestTest.java b/auth0/src/test/java/com/auth0/android/authentication/request/SignUpRequestTest.java index 595547c29..62697d46d 100644 --- a/auth0/src/test/java/com/auth0/android/authentication/request/SignUpRequestTest.java +++ b/auth0/src/test/java/com/auth0/android/authentication/request/SignUpRequestTest.java @@ -67,6 +67,14 @@ public void shouldSetScope() throws Exception { Assert.assertThat(req, is(signUpRequest)); } + @Test + public void shouldSetAudience() throws Exception { + final AuthenticationRequest req = signUpRequest.setAudience("https://domain.auth0.com/api"); + verify(authenticationMockRequest).setAudience("https://domain.auth0.com/api"); + Assert.assertThat(req, is(notNullValue())); + Assert.assertThat(req, Matchers.is(signUpRequest)); + } + @Test public void shouldSetDevice() throws Exception { final AuthenticationRequest req = signUpRequest.setDevice("nexus-5x"); diff --git a/auth0/src/test/java/com/auth0/android/request/internal/MockAuthenticationRequest.java b/auth0/src/test/java/com/auth0/android/request/internal/MockAuthenticationRequest.java index 76d71a9eb..2b2cda1cd 100644 --- a/auth0/src/test/java/com/auth0/android/request/internal/MockAuthenticationRequest.java +++ b/auth0/src/test/java/com/auth0/android/request/internal/MockAuthenticationRequest.java @@ -49,6 +49,11 @@ public AuthenticationRequest setDevice(String device) { return null; } + @Override + public AuthenticationRequest setAudience(String audience) { + return null; + } + @Override public AuthenticationRequest setAccessToken(String accessToken) { return null;