Skip to content

Commit ca5c4be

Browse files
committed
isUnauthorizedResponse
1 parent 95c5586 commit ca5c4be

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
public final class io/ktor/client/plugins/auth/AuthConfig {
22
public fun <init> ()V
33
public final fun getProviders ()Ljava/util/List;
4-
public final fun isUnauthorized ()Lkotlin/jvm/functions/Function2;
5-
public final fun setUnauthorized (Lkotlin/jvm/functions/Function2;)V
4+
public final fun isUnauthorizedResponse ()Lkotlin/jvm/functions/Function2;
5+
public final fun setUnauthorizedResponse (Lkotlin/jvm/functions/Function2;)V
66
}
77

88
public final class io/ktor/client/plugins/auth/AuthKt {

ktor-client/ktor-client-plugins/ktor-client-auth/api/ktor-client-auth.klib.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ final class io.ktor.client.plugins.auth/AuthConfig { // io.ktor.client.plugins.a
156156
final val providers // io.ktor.client.plugins.auth/AuthConfig.providers|{}providers[0]
157157
final fun <get-providers>(): kotlin.collections/MutableList<io.ktor.client.plugins.auth/AuthProvider> // io.ktor.client.plugins.auth/AuthConfig.providers.<get-providers>|<get-providers>(){}[0]
158158

159-
final var isUnauthorized // io.ktor.client.plugins.auth/AuthConfig.isUnauthorized|{}isUnauthorized[0]
160-
final fun <get-isUnauthorized>(): kotlin.coroutines/SuspendFunction1<io.ktor.client.statement/HttpResponse, kotlin/Boolean> // io.ktor.client.plugins.auth/AuthConfig.isUnauthorized.<get-isUnauthorized>|<get-isUnauthorized>(){}[0]
161-
final fun <set-isUnauthorized>(kotlin.coroutines/SuspendFunction1<io.ktor.client.statement/HttpResponse, kotlin/Boolean>) // io.ktor.client.plugins.auth/AuthConfig.isUnauthorized.<set-isUnauthorized>|<set-isUnauthorized>(kotlin.coroutines.SuspendFunction1<io.ktor.client.statement.HttpResponse,kotlin.Boolean>){}[0]
159+
final var isUnauthorizedResponse // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse|{}isUnauthorizedResponse[0]
160+
final fun <get-isUnauthorizedResponse>(): kotlin.coroutines/SuspendFunction1<io.ktor.client.statement/HttpResponse, kotlin/Boolean> // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse.<get-isUnauthorizedResponse>|<get-isUnauthorizedResponse>(){}[0]
161+
final fun <set-isUnauthorizedResponse>(kotlin.coroutines/SuspendFunction1<io.ktor.client.statement/HttpResponse, kotlin/Boolean>) // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse.<set-isUnauthorizedResponse>|<set-isUnauthorizedResponse>(kotlin.coroutines.SuspendFunction1<io.ktor.client.statement.HttpResponse,kotlin.Boolean>){}[0]
162162
}
163163

164164
final val io.ktor.client.plugins.auth/Auth // io.ktor.client.plugins.auth/Auth|{}Auth[0]

ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package io.ktor.client.plugins.auth
66

77
import io.ktor.client.*
88
import io.ktor.client.call.*
9-
import io.ktor.client.plugins.*
109
import io.ktor.client.plugins.api.*
1110
import io.ktor.client.request.*
1211
import io.ktor.client.statement.*
@@ -37,7 +36,7 @@ public class AuthConfig {
3736
/**
3837
* A lambda function to control whether a response is unauthorized and should trigger a refresh / re-auth.
3938
*/
40-
public var isUnauthorized: suspend (HttpResponse) -> Boolean = { it.status == HttpStatusCode.Unauthorized }
39+
public var isUnauthorizedResponse: suspend (HttpResponse) -> Boolean = { it.status == HttpStatusCode.Unauthorized }
4140
}
4241

4342
/**
@@ -140,14 +139,14 @@ public val Auth: ClientPlugin<AuthConfig> = createClientPlugin("Auth", ::AuthCon
140139

141140
on(Send) { originalRequest ->
142141
val origin = proceed(originalRequest)
143-
if (!pluginConfig.isUnauthorized(origin.response)) return@on origin
142+
if (!pluginConfig.isUnauthorizedResponse(origin.response)) return@on origin
144143
if (origin.request.attributes.contains(AuthCircuitBreaker)) return@on origin
145144

146145
var call = origin
147146

148147
val candidateProviders = HashSet(providers)
149148

150-
while (pluginConfig.isUnauthorized(call.response)) {
149+
while (pluginConfig.isUnauthorizedResponse(call.response)) {
151150
LOGGER.trace { "Unauthorized response for ${call.request.url}" }
152151

153152
val (provider, authHeader) = findProvider(call, candidateProviders) ?: run {

ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class AuthTest : ClientLoader() {
407407
fun testForbiddenBearerAuthWithInvalidAccessAndValidRefreshTokens() = clientTests {
408408
config {
409409
install(Auth) {
410-
isUnauthorized = { it.status == HttpStatusCode.Forbidden }
410+
isUnauthorizedResponse = { it.status == HttpStatusCode.Forbidden }
411411
bearer {
412412
refreshTokens { BearerTokens("valid", "refresh") }
413413
loadTokens { BearerTokens("invalid", "refresh") }

0 commit comments

Comments
 (0)