diff --git a/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.api b/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.api index c905c4023d8..209294981aa 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.api +++ b/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.api @@ -1,8 +1,8 @@ public final class io/ktor/client/plugins/auth/AuthConfig { public fun ()V public final fun getProviders ()Ljava/util/List; - public final fun isUnauthorized ()Lkotlin/jvm/functions/Function2; - public final fun setUnauthorized (Lkotlin/jvm/functions/Function2;)V + public final fun isUnauthorizedResponse ()Lkotlin/jvm/functions/Function2; + public final fun setUnauthorizedResponse (Lkotlin/jvm/functions/Function2;)V } public final class io/ktor/client/plugins/auth/AuthKt { diff --git a/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.klib.api b/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.klib.api index f232e6e1df6..63cead3b8f3 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.klib.api +++ b/ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.klib.api @@ -156,9 +156,9 @@ final class io.ktor.client.plugins.auth/AuthConfig { // io.ktor.client.plugins.a final val providers // io.ktor.client.plugins.auth/AuthConfig.providers|{}providers[0] final fun (): kotlin.collections/MutableList // io.ktor.client.plugins.auth/AuthConfig.providers.|(){}[0] - final var isUnauthorized // io.ktor.client.plugins.auth/AuthConfig.isUnauthorized|{}isUnauthorized[0] - final fun (): kotlin.coroutines/SuspendFunction1 // io.ktor.client.plugins.auth/AuthConfig.isUnauthorized.|(){}[0] - final fun (kotlin.coroutines/SuspendFunction1) // io.ktor.client.plugins.auth/AuthConfig.isUnauthorized.|(kotlin.coroutines.SuspendFunction1){}[0] + final var isUnauthorizedResponse // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse|{}isUnauthorizedResponse[0] + final fun (): kotlin.coroutines/SuspendFunction1 // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse.|(){}[0] + final fun (kotlin.coroutines/SuspendFunction1) // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse.|(kotlin.coroutines.SuspendFunction1){}[0] } final val io.ktor.client.plugins.auth/Auth // io.ktor.client.plugins.auth/Auth|{}Auth[0] diff --git a/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt b/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt index 3cdcf925784..31ef42a1f59 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt +++ b/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt @@ -6,7 +6,6 @@ package io.ktor.client.plugins.auth import io.ktor.client.* import io.ktor.client.call.* -import io.ktor.client.plugins.* import io.ktor.client.plugins.api.* import io.ktor.client.request.* import io.ktor.client.statement.* @@ -37,7 +36,7 @@ public class AuthConfig { /** * A lambda function to control whether a response is unauthorized and should trigger a refresh / re-auth. */ - public var isUnauthorized: suspend (HttpResponse) -> Boolean = { it.status == HttpStatusCode.Unauthorized } + public var isUnauthorizedResponse: suspend (HttpResponse) -> Boolean = { it.status == HttpStatusCode.Unauthorized } } /** @@ -140,14 +139,14 @@ public val Auth: ClientPlugin = createClientPlugin("Auth", ::AuthCon on(Send) { originalRequest -> val origin = proceed(originalRequest) - if (!pluginConfig.isUnauthorized(origin.response)) return@on origin + if (!pluginConfig.isUnauthorizedResponse(origin.response)) return@on origin if (origin.request.attributes.contains(AuthCircuitBreaker)) return@on origin var call = origin val candidateProviders = HashSet(providers) - while (pluginConfig.isUnauthorized(call.response)) { + while (pluginConfig.isUnauthorizedResponse(call.response)) { LOGGER.trace { "Unauthorized response for ${call.request.url}" } val (provider, authHeader) = findProvider(call, candidateProviders) ?: run { diff --git a/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt b/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt index 6bbcd0001d6..6c6a236f175 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt +++ b/ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt @@ -407,7 +407,7 @@ class AuthTest : ClientLoader() { fun testForbiddenBearerAuthWithInvalidAccessAndValidRefreshTokens() = clientTests { config { install(Auth) { - isUnauthorized = { it.status == HttpStatusCode.Forbidden } + isUnauthorizedResponse = { it.status == HttpStatusCode.Forbidden } bearer { refreshTokens { BearerTokens("valid", "refresh") } loadTokens { BearerTokens("invalid", "refresh") }