Hi, we have a native Android app and native iOS app and are starting with Kotlin Multiplatform. For networking Android uses Retrofit/OkHttp and iOS uses Alamofire. We use OAuth as authentication for our app. Android uses Authenticator from OkHttp to setup refresh token mechanism. On iOS a RequestInterceptor from Alamofire is used. These interceptors also open an error screen when an unrecoverable authentication error occurs.
I’m now setting up Ktor in our first KMP module to start sharing some API requests between Android and iOS. This also needs the same refresh token mechanism. For Android I can use Ktor with a preconfigured OkHttpClient. This would be the same OkHttpClient as in the native Android app. For Ktor on iOS there isn’t a way to reuse the same Alamofire Interceptors if I’m correct.
So what would be the best approach to set this up? Do I need to implement the refresh token mechanism in Ktor separately? Then I would have duplicate refresh token mechanisms in KMP and in native iOS.
Do you know any good articles or Github samples for this setup?
v
Vidmantas Kerbelis
11/05/2025, 12:31 PM
Personally, I would re-implement in Ktor in shared code without using the OkHttpClient's interceptor in the Android source set and regression test it.
Eventually,
All of the OkHttpClient's interceptors and all logic -> Scrapped
Alamofire implementation -> Scrapped