Skip to content

Commit

Permalink
Revert changes from #654. Fix renew Credentials logic (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj authored Jul 17, 2023
1 parent 81b516e commit f90820e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
* @return a request to start
*/
public fun renewAuth(refreshToken: String): Request<Credentials, AuthenticationException> {
val parameters = ParameterBuilder.newBuilderWithRequiredScope()
val parameters = ParameterBuilder.newBuilder()
.setClientId(clientId)
.setRefreshToken(refreshToken)
.setGrantType(ParameterBuilder.GRANT_TYPE_REFRESH_TOKEN)
Expand Down Expand Up @@ -690,7 +690,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
codeVerifier: String,
redirectUri: String
): Request<Credentials, AuthenticationException> {
val parameters = ParameterBuilder.newBuilderWithRequiredScope()
val parameters = ParameterBuilder.newBuilder()
.setClientId(clientId)
.setGrantType(ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE)
.set(OAUTH_CODE_KEY, authorizationCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ public class ParameterBuilder private constructor(parameters: Map<String, String
.setScope(OidcUtils.DEFAULT_SCOPE)
}

@JvmStatic
public fun newBuilderWithRequiredScope(): ParameterBuilder {
return newBuilder()
.setScope(OidcUtils.REQUIRED_SCOPE)
}

/**
* Creates a new instance of the builder.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.auth0.android.request.internal

import androidx.annotation.VisibleForTesting
import java.util.*

/**
Expand All @@ -9,7 +8,7 @@ import java.util.*
internal object OidcUtils {
internal const val KEY_SCOPE = "scope"
internal const val DEFAULT_SCOPE = "openid profile email"
internal const val REQUIRED_SCOPE = "openid"
private const val REQUIRED_SCOPE = "openid"

/**
* Given a string, it will check if it contains the scope of "openid".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.auth0.android.request.HttpMethod
import com.auth0.android.request.NetworkingClient
import com.auth0.android.request.RequestOptions
import com.auth0.android.request.ServerResponse
import com.auth0.android.request.internal.OidcUtils
import com.auth0.android.request.internal.RequestFactory
import com.auth0.android.request.internal.ThreadSwitcherShadow
import com.auth0.android.result.*
Expand Down Expand Up @@ -2201,7 +2200,7 @@ public class AuthenticationAPIClientTest {
)
assertThat(request.path, Matchers.equalTo("/oauth/token"))
val body = bodyFromRequest<String>(request)
assertThat(body, Matchers.hasEntry("scope", OidcUtils.REQUIRED_SCOPE))
assertThat(body, Matchers.not(Matchers.hasKey("scope")))
assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID))
assertThat(body, Matchers.hasEntry("refresh_token", "refreshToken"))
assertThat(body, Matchers.hasEntry("grant_type", "refresh_token"))
Expand Down Expand Up @@ -2230,7 +2229,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.hasEntry("scope", OidcUtils.REQUIRED_SCOPE))
assertThat(body, Matchers.not(Matchers.hasKey("scope")))
assertThat(credentials, Matchers.`is`(Matchers.notNullValue()))
}

Expand All @@ -2253,7 +2252,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.hasEntry("scope", OidcUtils.REQUIRED_SCOPE))
assertThat(body, Matchers.not(Matchers.hasKey("scope")))
assertThat(credentials, Matchers.`is`(Matchers.notNullValue()))
}

Expand Down Expand Up @@ -2364,7 +2363,6 @@ 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
Expand All @@ -2390,7 +2388,6 @@ 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
Expand Down

0 comments on commit f90820e

Please sign in to comment.