On the client, is there a way to trigger token ref...
# ktor
u
On the client, is there a way to trigger token refresh behavior if access token is deemed expired locally? i.e. to refresh & retry without getting the 401 from server?
s
I filed https://youtrack.jetbrains.com/issue/KTOR-6419/Auth-Add-ability-to-provide-a-callback-to-tell-the-plugin-if-tokens-are-expired to solve exactly this issue. Without it, I don't think there is a way today.
a
If you monitor token expiration, you can call the BearerAuthProvider.refreshToken method (if the token has expired) to refresh it and save a new one in the storage.
u
will it be "thread" safe if concurrent requests are hitting it & do retries etc? basically exactly how does the refresh pipeline behave if triggered by response code?
a
Unfortunately, no. The storage update is synchronized, but the request queue, which prevents double-refresh, is implemented in a higher-level private function.
u
yea I figured, hence trying to somehow trigger the singular refresh pipeline