Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
wkornewald committed Nov 15, 2024
1 parent f5535bd commit 6680b91
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public final class io/ktor/client/plugins/auth/AuthConfig {
public fun <init> ()V
public final fun getProviders ()Ljava/util/List;
public final fun isUnauthorizedResponse ()Lkotlin/jvm/functions/Function2;
public final fun setUnauthorizedResponse (Lkotlin/jvm/functions/Function2;)V
public final fun reAuthorizeOnResponse (Lkotlin/jvm/functions/Function2;)V
}

public final class io/ktor/client/plugins/auth/AuthKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ final class io.ktor.client.plugins.auth/AuthConfig { // io.ktor.client.plugins.a

final var isUnauthorizedResponse // io.ktor.client.plugins.auth/AuthConfig.isUnauthorizedResponse|{}isUnauthorizedResponse[0]
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]
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]

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]
}

final val io.ktor.client.plugins.auth/Auth // io.ktor.client.plugins.auth/Auth|{}Auth[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,23 @@ public class AuthConfig {
public val providers: MutableList<AuthProvider> = mutableListOf()

/**
* A lambda function to control whether a response is unauthorized and should trigger a refresh / re-auth.
* The currently set function to control whether a response is unauthorized and should trigger a refresh / re-auth.
*
* By default checks against HTTP status 401.
*
* You can set this value via [reAuthorizeOnResponse].
*/
public var isUnauthorizedResponse: suspend (HttpResponse) -> Boolean = { it.status == HttpStatusCode.Unauthorized }
private set

/**
* Sets a custom function to control whether a response is unauthorized and should trigger a refresh / re-auth.
*
* Use this to change the value of [isUnauthorizedResponse].
*/
public fun reAuthorizeOnResponse(block: suspend (HttpResponse) -> Boolean) {
isUnauthorizedResponse = block
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class AuthTest : ClientLoader() {
fun testForbiddenBearerAuthWithInvalidAccessAndValidRefreshTokens() = clientTests {
config {
install(Auth) {
isUnauthorizedResponse = { it.status == HttpStatusCode.Forbidden }
reAuthorizeOnResponse { it.status == HttpStatusCode.Forbidden }
bearer {
refreshTokens { BearerTokens("valid", "refresh") }
loadTokens { BearerTokens("invalid", "refresh") }
Expand Down

0 comments on commit 6680b91

Please sign in to comment.