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

xxfast

02/28/2023, 10:48 PM
Hi all. Is there a way to configure
ktor-client
to not reuse
loadTokens
/
defaultRequest
for subsequent requests, i.e a way to always invoke
defaultRequest
every time a request is made? Use-case in 🧵
I load my tokens from disk
Copy code
Auth {
  bearer {
    loadTokens {
      val credentials: DeviceCredentials = store.get() 
      BearerTokens(
        accessToken = credentials.access_token.encoded,
        refreshToken = credentials.refresh_token.encoded
      )
    }
  }
}
but stored token can change overtime, and when it does, my ktor client is still using the old token
a

Aleksei Tirman [JB]

03/01/2023, 4:55 PM
So you want the
loadTokens
block to be called each time a request is made?
x

xxfast

03/01/2023, 8:49 PM
Yes, same behaviour for
defaultRequest
Not sure if this is doable 🫠
a

Aleksei Tirman [JB]

03/02/2023, 6:45 AM
Unfortunately, it’s not configurable that way. You can try to detect when the file is changed and call the clearToken method to remove the cache.
5 Views