Calogero
02/23/2023, 11:20 PMclient.plugin(Auth).providers.filterIsInstance<BearerAuthProvider>().first().clearToken()
I’m clearing the tokens so that when the user login again the app doesn’t reuse the tokens loaded in memory during the previous session.
If I understood it correclty, clearing the AuthTokenHolder instance is needed for let the condition on this line to be false, so that the code can continue and execute the line 38. Then, alle the subsequent call to loadToken should return on line 35 unless the refreshTokensDeferred variable is set to null.
After clearing the holder, I expect the loadTokens function to be called again, so that the code can fetch the new tokens obtained after the new login of the user.
Unfortunately, it doesn’t happen and the first call using the Authorization header is using the access token used during the previous session.
Can you guys help me on that?
Thanks!Aleksei Tirman [JB]
02/24/2023, 8:07 AMCalogero
02/24/2023, 8:09 AMinstall("HeaderChanger") { interceptHttpResponse(receivePipeline) }
@InternalAPI
private fun interceptHttpResponse(receivePipeline: HttpReceivePipeline) {
receivePipeline.intercept(HttpReceivePipeline.Before) { response ->
if (response.status.value != Constants.Network.ErrorCodes.UNAUTHORIZED) {
proceedWith(response)
return@intercept
}
val newResponse = object : HttpResponse() {
override val call: HttpClientCall = response.call
override val content: ByteReadChannel = response.content
override val coroutineContext = response.coroutineContext
override val headers: Headers = HeadersBuilder().apply {
remove(HttpHeaders.WWWAuthenticate)
append(HttpHeaders.WWWAuthenticate, "Bearer")
}.build()
override val requestTime: GMTDate = response.requestTime
override val responseTime: GMTDate = response.responseTime
override val status: HttpStatusCode = response.status
override val version: HttpProtocolVersion = response.version
}
this.proceedWith(newResponse)
}
}
How harmful is that?Aleksei Tirman [JB]
03/01/2023, 10:07 AM