From 62f915288a34a70741e173dd6b936328f03eaf43 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Mon, 21 Nov 2016 21:44:24 -0300 Subject: [PATCH 1/2] Added test for scope being overriden by default --- .../android/provider/WebAuthProviderTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java index 0d5d86d27..eb195c10c 100644 --- a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java +++ b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java @@ -10,6 +10,7 @@ import com.auth0.android.Auth0; import com.auth0.android.authentication.AuthenticationException; +import com.auth0.android.authentication.ParameterBuilder; import com.auth0.android.result.Credentials; import org.hamcrest.Matchers; @@ -25,6 +26,7 @@ import org.mockito.stubbing.Answer; import org.robolectric.Robolectric; import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.util.HashMap; @@ -57,7 +59,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) @Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 18, manifest = Config.NONE) public class WebAuthProviderTest { @@ -146,6 +148,17 @@ public void shouldHaveDefaultScope() throws Exception { assertThat(instance.getScope(), is(SCOPE_OPEN_ID)); } + @Test + public void shouldNotOverrideScopeValue() throws Exception { + Map parameters = ParameterBuilder.newBuilder().setScope("openid email picture").asDictionary(); + WebAuthProvider.init(account) + .withParameters(parameters) + .start(activity, callback); + + final WebAuthProvider instance = WebAuthProvider.getInstance(); + assertThat(instance.getScope(), is("openid email picture")); + } + @Test public void shouldCallStartWithRequestCode() throws Exception { WebAuthProvider.init(account) From b4a173a62fc73e9cfd3de2b1653d2d5f7fe32df4 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Mon, 21 Nov 2016 22:02:42 -0300 Subject: [PATCH 2/2] Avoid scope to be overriden --- .../com/auth0/android/provider/WebAuthProvider.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java index 21f6093dd..5587552b5 100644 --- a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java +++ b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java @@ -118,7 +118,7 @@ public static class Builder { this.useCodeGrant = true; this.parameters = new HashMap<>(); this.state = UUID.randomUUID().toString(); - this.scope = SCOPE_TYPE_OPENID; + this.scope = null; } /** @@ -439,10 +439,8 @@ private Uri buildAuthorizeUri() { if (account.getTelemetry() != null) { queryParameters.put(KEY_TELEMETRY, account.getTelemetry().getValue()); } - if (scope != null) { - queryParameters.put(KEY_SCOPE, scope); - } + queryParameters.put(KEY_SCOPE, getScope()); queryParameters.put(KEY_STATE, state); queryParameters.put(KEY_CONNECTION, connectionName); queryParameters.put(KEY_CLIENT_ID, account.getClientId()); @@ -481,7 +479,10 @@ String getState() { } String getScope() { - return scope; + if (this.scope != null) { + return this.scope; + } + return this.parameters.get(KEY_SCOPE) != null ? (String) this.parameters.get(KEY_SCOPE) : SCOPE_TYPE_OPENID; } String getConnectionScope() {