Skip to content

Commit 6680b91

Browse files
committed
PR review
1 parent f5535bd commit 6680b91

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ public final class io/ktor/client/plugins/auth/AuthConfig {
22
public fun <init> ()V
33
public final fun getProviders ()Ljava/util/List;
44
public final fun isUnauthorizedResponse ()Lkotlin/jvm/functions/Function2;
5-
public final fun setUnauthorizedResponse (Lkotlin/jvm/functions/Function2;)V
5+
public final fun reAuthorizeOnResponse (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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ final class io.ktor.client.plugins.auth/AuthConfig { // io.ktor.client.plugins.a
158158

159159
final var isUnauthorizedResponse // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse|{}isUnauthorizedResponse[0]
160160
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]
161+
162+
final fun reAuthorizeOnResponse(kotlin.coroutines/SuspendFunction1<io.ktor.client.statement/HttpResponse, kotlin/Boolean>) // io.ktor.client.plugins.auth/AuthConfig.reAuthorizeOnResponse|reAuthorizeOnResponse(kotlin.coroutines.SuspendFunction1<io.ktor.client.statement.HttpResponse,kotlin.Boolean>){}[0]
162163
}
163164

164165
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,23 @@ public class AuthConfig {
3434
public val providers: MutableList<AuthProvider> = mutableListOf()
3535

3636
/**
37-
* A lambda function to control whether a response is unauthorized and should trigger a refresh / re-auth.
37+
* The currently set function to control whether a response is unauthorized and should trigger a refresh / re-auth.
38+
*
39+
* By default checks against HTTP status 401.
40+
*
41+
* You can set this value via [reAuthorizeOnResponse].
3842
*/
3943
public var isUnauthorizedResponse: suspend (HttpResponse) -> Boolean = { it.status == HttpStatusCode.Unauthorized }
44+
private set
45+
46+
/**
47+
* Sets a custom function to control whether a response is unauthorized and should trigger a refresh / re-auth.
48+
*
49+
* Use this to change the value of [isUnauthorizedResponse].
50+
*/
51+
public fun reAuthorizeOnResponse(block: suspend (HttpResponse) -> Boolean) {
52+
isUnauthorizedResponse = block
53+
}
4054
}
4155

4256
/**

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-
isUnauthorizedResponse = { it.status == HttpStatusCode.Forbidden }
410+
reAuthorizeOnResponse { it.status == HttpStatusCode.Forbidden }
411411
bearer {
412412
refreshTokens { BearerTokens("valid", "refresh") }
413413
loadTokens { BearerTokens("invalid", "refresh") }

0 commit comments

Comments
 (0)