From 0f1a3cd879c6960e41ddb309d6502c0fd2619bd2 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Tue, 2 May 2023 17:16:01 +0530 Subject: [PATCH] Add required scopes to token and renewAuth requests --- .../android/authentication/AuthenticationAPIClient.kt | 4 ++-- .../com/auth0/android/authentication/ParameterBuilder.kt | 6 ++++++ .../java/com/auth0/android/request/internal/OidcUtils.kt | 4 +++- .../authentication/AuthenticationAPIClientTest.kt | 9 ++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt index eeb144a1..5a14a892 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt +++ b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt @@ -555,7 +555,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe * @return a request to start */ public fun renewAuth(refreshToken: String): Request { - val parameters = ParameterBuilder.newBuilder() + val parameters = ParameterBuilder.newBuilderWithRequiredScope() .setClientId(clientId) .setRefreshToken(refreshToken) .setGrantType(ParameterBuilder.GRANT_TYPE_REFRESH_TOKEN) @@ -690,7 +690,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe codeVerifier: String, redirectUri: String ): Request { - val parameters = ParameterBuilder.newBuilder() + val parameters = ParameterBuilder.newBuilderWithRequiredScope() .setClientId(clientId) .setGrantType(ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE) .set(OAUTH_CODE_KEY, authorizationCode) diff --git a/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.kt b/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.kt index 3364e111..91a82a23 100755 --- a/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.kt +++ b/auth0/src/main/java/com/auth0/android/authentication/ParameterBuilder.kt @@ -181,6 +181,12 @@ public class ParameterBuilder private constructor(parameters: Map(request) - assertThat(body, Matchers.not(Matchers.hasKey("scope"))) + assertThat(body, Matchers.hasEntry("scope", OidcUtils.REQUIRED_SCOPE)) assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID)) assertThat(body, Matchers.hasEntry("refresh_token", "refreshToken")) assertThat(body, Matchers.hasEntry("grant_type", "refresh_token")) @@ -2229,7 +2230,7 @@ public class AuthenticationAPIClientTest { assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID)) assertThat(body, Matchers.hasEntry("refresh_token", "refreshToken")) assertThat(body, Matchers.hasEntry("grant_type", "refresh_token")) - assertThat(body, Matchers.not(Matchers.hasKey("scope"))) + assertThat(body, Matchers.hasEntry("scope", OidcUtils.REQUIRED_SCOPE)) assertThat(credentials, Matchers.`is`(Matchers.notNullValue())) } @@ -2252,7 +2253,7 @@ public class AuthenticationAPIClientTest { assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID)) assertThat(body, Matchers.hasEntry("refresh_token", "refreshToken")) assertThat(body, Matchers.hasEntry("grant_type", "refresh_token")) - assertThat(body, Matchers.not(Matchers.hasKey("scope"))) + assertThat(body, Matchers.hasEntry("scope", OidcUtils.REQUIRED_SCOPE)) assertThat(credentials, Matchers.`is`(Matchers.notNullValue())) } @@ -2363,6 +2364,7 @@ public class AuthenticationAPIClientTest { assertThat(body, Matchers.hasEntry("code", "code")) assertThat(body, Matchers.hasEntry("code_verifier", "codeVerifier")) assertThat(body, Matchers.hasEntry("redirect_uri", "http://redirect.uri")) + assertThat(body, Matchers.hasEntry("scope", OidcUtils.REQUIRED_SCOPE)) assertThat( callback, AuthenticationCallbackMatcher.hasPayloadOfType( Credentials::class.java @@ -2388,6 +2390,7 @@ public class AuthenticationAPIClientTest { assertThat(body, Matchers.hasEntry("code", "code")) assertThat(body, Matchers.hasEntry("code_verifier", "codeVerifier")) assertThat(body, Matchers.hasEntry("redirect_uri", "http://redirect.uri")) + assertThat(body, Matchers.hasEntry("scope", OidcUtils.REQUIRED_SCOPE)) assertThat( callback, AuthenticationCallbackMatcher.hasError( Credentials::class.java