On a client i would like to use JWT auth. These JWT expires sometimes, so i would like to intercept every request and look for a 401 or 403 response, refresh my token and retry the request. How do i do this? I found
HttpResponseValidator
which seems useful, but how do i:
1. Perform a refresh request
2. Retry the failed request
Perhaps im better off wrapping my ktor calls in a helper, and handle it there instead of trying to use
HttpResponseValidator
?
j
jorge.rego
08/13/2020, 12:39 PM
How do you do that in your server or in your client?
jorge.rego
08/13/2020, 12:40 PM
In server side you can install JWT Authentication feature and validate tokens by JWT validator. All routes inside authentication will require to pass the JWT validator. Here you can find an example:
https://github.com/mathias21/KtorEasy
m
Mgj
08/13/2020, 12:41 PM
In my client
j
jorge.rego
08/13/2020, 1:31 PM
Ktor doc is not saying anything about how to deal with token refresh, but in OkHttp3 Android you would implement a token Authenticator that will process token refresh when 401 is returned.
m
Mgj
08/13/2020, 1:38 PM
Yeah something like that would be great. Im unsure if its part of retrofit or okhttp but the `authenticator`class is very very useful for this purpose, or the more generalized interceptors.
But i want to use something shared across the different platforms in my KMP project