@@ -26,6 +26,7 @@ private class AtomicCounter {
2626@KtorDsl
2727public class AuthConfig {
2828 public val providers: MutableList <AuthProvider > = mutableListOf ()
29+ public val reAuthStatusCodes: MutableList <HttpStatusCode > = mutableListOf (HttpStatusCode .Unauthorized )
2930}
3031
3132/* *
@@ -40,6 +41,7 @@ public val AuthCircuitBreaker: AttributeKey<Unit> = AttributeKey("auth-request")
4041 * You can learn more from [Authentication and authorization](https://ktor.io/docs/auth.html).
4142 *
4243 * [providers] - list of auth providers to use.
44+ * [reAuthStatusCodes] - list of [HttpStatusCode] values which trigger a re-auth.
4345 */
4446public val Auth : ClientPlugin <AuthConfig > = createClientPlugin(" Auth" , ::AuthConfig ) {
4547 val providers = pluginConfig.providers.toList()
@@ -128,14 +130,14 @@ public val Auth: ClientPlugin<AuthConfig> = createClientPlugin("Auth", ::AuthCon
128130
129131 on(Send ) { originalRequest ->
130132 val origin = proceed(originalRequest)
131- if (origin.response.status != HttpStatusCode . Unauthorized ) return @on origin
133+ if (origin.response.status !in pluginConfig.reAuthStatusCodes ) return @on origin
132134 if (origin.request.attributes.contains(AuthCircuitBreaker )) return @on origin
133135
134136 var call = origin
135137
136138 val candidateProviders = HashSet (providers)
137139
138- while (call.response.status == HttpStatusCode . Unauthorized ) {
140+ while (call.response.status in pluginConfig.reAuthStatusCodes ) {
139141 LOGGER .trace(" Received 401 for ${call.request.url} " )
140142
141143 val (provider, authHeader) = findProvider(call, candidateProviders) ? : run {
0 commit comments