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

Harrison

08/19/2021, 8:15 AM
Hi there, I am trying to get Ktor client to trigger a token refresh when getting a 401. Unfortunately the api is not setting the correct auth scheme in the response header. They are using “default” when the BearerAuthProvider expects “bearer” obviously. This prevents the token refresh logic from being run. Any ideas on a not so hacky way around this?
r

ribesg

08/19/2021, 8:37 AM
They declined this problem for some reason https://youtrack.jetbrains.com/issue/KTOR-2806
The current solution is to have your own Auth feature. I actually never used the provided Auth feature as it always had multiple problems. This one remains…
I think that their point is that if you want to handle all 401 as the sole info needed to trigger token refresh, then you should modify the server response inside the client pipeline before the Auth feature gets triggered to make it look like whatever response their (standard) implementation of auth is expecting. I would prefer some kind of
shouldTriggerTokenRefresh
function we could override somewhere in the feature, but oh well
h

Harrison

08/19/2021, 8:42 AM
Thanks for the info 🙂 Any ideas on how to modify the response before it gets to the auth feature?
I would prefer not to copy and paste the whole auth feature, kinda defeats the purpose of using ktor client for me…
r

ribesg

08/19/2021, 8:47 AM
I actually wrote my Auth feature before Ktor had one so it was less of a problem for me 🙃
I have no idea when 2.0.0 is planned
h

Harrison

08/19/2021, 8:49 AM
Was something planed for this?
Well thanks for the info Gael. I appreciate it 🙂
a

Aleksei Tirman [JB]

08/19/2021, 9:16 AM
Ktor 2.0.0 is planned to be released at the end of October.
👍 1
🙌 1
4 Views