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 26528a4ea..57fe9353d 100644 --- a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java +++ b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.java @@ -1,4 +1,3 @@ - /* * WebAuthProvider.java * @@ -35,7 +34,6 @@ import android.util.Log; import com.auth0.android.Auth0; -import com.auth0.android.auth0.R; import com.auth0.android.authentication.AuthenticationAPIClient; import com.auth0.android.authentication.AuthenticationException; import com.auth0.android.result.Credentials; @@ -66,6 +64,7 @@ public class WebAuthProvider { private static final String KEY_CLIENT_ID = "client_id"; private static final String KEY_REDIRECT_URI = "redirect_uri"; private static final String KEY_SCOPE = "scope"; + private static final String KEY_CONNECTION_SCOPE = "connection_scope"; private static final String KEY_TELEMETRY = "auth0Client"; private static final String ERROR_VALUE_ACCESS_DENIED = "access_denied"; @@ -87,6 +86,7 @@ public class WebAuthProvider { private boolean useBrowser; private String state; private String scope; + private String connectionScope; private boolean useCodeGrant; private Map parameters; private String connectionName; @@ -105,6 +105,7 @@ public static class Builder { private boolean useFullscreen; private String state; private String scope; + private String connectionScope; private boolean useCodeGrant; private Map parameters; private String connectionName; @@ -127,6 +128,7 @@ public static class Builder { * If the class authenticates with an external browser or not. * * @param useBrowser if the authentication is handled in a Browser. + * @return the current builder instance */ public Builder useBrowser(boolean useBrowser) { this.useBrowser = useBrowser; @@ -138,6 +140,7 @@ public Builder useBrowser(boolean useBrowser) { * Browser authentication. * * @param useFullscreen if the activity should be fullscreen or not. + * @return the current builder instance */ public Builder useFullscreen(boolean useFullscreen) { this.useFullscreen = useFullscreen; @@ -148,6 +151,7 @@ public Builder useFullscreen(boolean useFullscreen) { * Use a custom state in the requests * * @param state to use in the requests + * @return the current builder instance */ public Builder withState(@NonNull String state) { this.state = state; @@ -158,16 +162,29 @@ public Builder withState(@NonNull String state) { * Give a scope for this request. * * @param scope to request. + * @return the current builder instance */ public Builder withScope(@NonNull String scope) { this.scope = scope; return this; } + /** + * Give a connection scope for this request. + * + * @param connectionScope to request. + * @return the current builder instance + */ + public Builder withConnectionScope(@NonNull String connectionScope) { + this.connectionScope = connectionScope; + return this; + } + /** * Choose the grant type for this request. * * @param useCodeGrant whether use code or implicit grant type + * @return the current builder instance */ public Builder useCodeGrant(boolean useCodeGrant) { this.useCodeGrant = useCodeGrant; @@ -178,6 +195,7 @@ public Builder useCodeGrant(boolean useCodeGrant) { * Use extra parameters on the request * * @param parameters to add + * @return the current builder instance */ public Builder withParameters(@Nullable Map parameters) { this.parameters = parameters != null ? new HashMap<>(parameters) : new HashMap(); @@ -188,6 +206,7 @@ public Builder withParameters(@Nullable Map parameters) { * Use the given connection instead of the default 'auth0'. * * @param connectionName to use + * @return the current builder instance */ public Builder withConnection(@NonNull String connectionName) { this.connectionName = connectionName; @@ -215,6 +234,7 @@ public void start(@NonNull Activity activity, @NonNull AuthCallback callback, in webAuth.useFullscreen = useFullscreen; webAuth.state = state; webAuth.scope = scope; + webAuth.connectionScope = connectionScope; webAuth.useCodeGrant = useCodeGrant; webAuth.parameters = parameters; webAuth.connectionName = connectionName; @@ -370,6 +390,7 @@ private Uri buildAuthorizeUri() { final Map queryParameters = new HashMap<>(); queryParameters.put(KEY_SCOPE, scope); + queryParameters.put(KEY_CONNECTION_SCOPE, connectionScope); queryParameters.put(KEY_RESPONSE_TYPE, RESPONSE_TYPE_TOKEN); if (shouldUsePKCE()) { @@ -436,6 +457,10 @@ String getScope() { return scope; } + String getConnectionScope() { + return connectionScope; + } + boolean useCodeGrant() { return useCodeGrant; } 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 39feb5fe1..cc0b73cdd 100644 --- a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java +++ b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.java @@ -65,6 +65,7 @@ public class WebAuthProviderTest { private static final int REQUEST_CODE = 11; private static final String CONNECTION_NAME = "connection"; private static final String SCOPE = "scope"; + private static final String CONNECTION_SCOPE = "connection_scope"; private static final String STATE = "state"; private static final String USERNAME_PASSWORD_AUTHENTICATION_CONNECTION = "Username-Password-Authentication"; private static final String SCOPE_OPEN_ID = "openid"; @@ -121,6 +122,7 @@ public void shouldHaveDefaultsOnInit() throws Exception { assertThat(instance.useFullscreen(), is(false)); assertThat(instance.getConnection(), is(not(Matchers.isEmptyOrNullString()))); assertThat(instance.getScope(), is(not(Matchers.isEmptyOrNullString()))); + assertThat(instance.getConnectionScope(), is(nullValue())); assertThat(instance.getState(), is(not(Matchers.isEmptyOrNullString()))); assertThat(instance.getParameters(), is(notNullValue())); assertThat(instance.getParameters().isEmpty(), is(true)); @@ -155,6 +157,7 @@ public void shouldConfigureAfterInit() throws Exception { .useFullscreen(true) .withConnection(CONNECTION_NAME) .withScope(SCOPE) + .withConnectionScope(CONNECTION_SCOPE) .withState(STATE) .withParameters(parameters) .start(activity, callback, REQUEST_CODE); @@ -165,6 +168,7 @@ public void shouldConfigureAfterInit() throws Exception { assertThat(instance.useFullscreen(), is(true)); assertThat(instance.getConnection(), is(CONNECTION_NAME)); assertThat(instance.getScope(), is(SCOPE)); + assertThat(instance.getConnectionScope(), is(CONNECTION_SCOPE)); assertThat(instance.getState(), is(STATE)); assertThat(instance.getParameters(), is(notNullValue())); assertThat(instance.getParameters(), Matchers.hasEntry("key", (Object) "value")); @@ -194,6 +198,7 @@ public void shouldBuildAuthorizeURI() throws Exception { .withConnection("my-connection") .withState("a-state") .withScope("super_scope") + .withConnectionScope("super_connection_scope") .withParameters(parameters) .start(activity, callback, REQUEST_CODE); @@ -209,6 +214,7 @@ public void shouldBuildAuthorizeURI() throws Exception { assertThat(intentCaptor.getValue().getData(), hasParamWithValue("connection", "my-connection")); assertThat(intentCaptor.getValue().getData(), hasParamWithValue("state", "a-state")); assertThat(intentCaptor.getValue().getData(), hasParamWithValue("scope", "super_scope")); + assertThat(intentCaptor.getValue().getData(), hasParamWithValue("connection_scope", "super_connection_scope")); assertThat(intentCaptor.getValue().getData(), hasParamWithValue("custom_param_1", "custom_value_1")); assertThat(intentCaptor.getValue().getData(), hasParamWithValue("custom_param_2", "custom_value_2")); assertThat(intentCaptor.getValue().getData(), hasParamWithValue("client_id", account.getClientId()));