https://kotlinlang.org logo
#ktor
Title
# ktor
s

Sudhanshu Singh

09/06/2023, 5:18 PM
refreshTokens
block isn't called when api throws 401
Copy code
engine {
     preconfigured = okHttpClient
 }
install(Auth) {
                bearer {
                    loadTokens {
                        BearerTokens(
                                preferencesHelper.sessionToken,
                                preferencesHelper.sessionToken
                            )
                    }
                    refreshTokens {
                        // this block doesn't get executed
                        val response = <http://client.post|client.post> {
                            markAsRefreshTokenRequest()
                            url("<http://www.host.com/1/token|www.host.com/1/token>"))
                        }.body<Token>()
                        preferencesHelper.sessionToken = response.token
                        BearerTokens(
                            accessToken = response.token,
                            refreshToken = response.token,
                        )
                    }
                }
            }
for example an api gives below 401 response
Copy code
code: 401
 internal: {}
 message: "square/go-jose/jwt: validation failed, token is expired (exp)"
a

Aleksei Tirman [JB]

09/06/2023, 7:24 PM
What value the server sends for the
WWW-Authenticate
header?
s

Sudhanshu Singh

09/06/2023, 7:25 PM
nothing. we don't use this header
a

Aleksei Tirman [JB]

09/06/2023, 7:34 PM
Without that header refreshTokens's lambda won't get called.
2 Views