I'm moving an app from android only to ios + andro...
# ktor
c
I'm moving an app from android only to ios + android using kmp. I was using okhttp with interceptors as well as an authenticator. Since im still new to ktor... I'm trying to connect the dots on what i would do here as it seems like ktor uses okhttp under the hood on android. it seems like i should be able to connect my interceptor (which is pretty basic as its just adding a header) + my authenticator mechanism easily to android, but how would i go about adding those to ios?
s
Migrate that to a ktor interceptor instead I think is your best bet. For auth there is an auth plugin specifically made for this functionality. (edit: this perhaps https://ktor.io/docs/client-auth.html#install_plugin) Quick googling made me go here https://ktor.io/docs/server-custom-plugins.html#on-call I haven't done this for ktor, but I have for apollo-kotlin, where I also had interceptors in OkHttp land, but I just had to migrate them to the apollo-kotlin multiplatform compatible interceptors instead. So it should be the same here I would guess.
c
oh cool. i was looking at ktor auth but couldn't really find a way to include my sorta complex auth interceptor thing. i didn't know that ktor had an interceptor concept
thanks!
s
Why doesn't the auth plugin suit your needs?
c
1: i think the first major thing is that my current okhttp authenticator expects to only be called after a 401/403/whatever. https://square.github.io/okhttp/3.x/okhttp/okhttp3/Authenticator.html 2: Looks like the auth that my auth falls under would be Bearer, but we're using "firebase auth w/ your own server" (see: https://firebase.google.com/docs/auth "Custom auth system integration". so basically. I just need to intercept a 401/403 and try to call firebase.refresh and then call my server again. its kinda annoying. but it works great with okhttp authenticator. but i suppose I should just be able to roll my own with ktor
Aha. under all hooks there seems to be a hook that i can use. lemme see if i can whip something up
ah cool. okay so i was able to use this as a template https://ktor.io/docs/client-custom-plugins.html#authentication i still dont necessarily understand when ktor will retry a request, but i have something sorta working and should be able to get this finished up. WOOT. 1 step closer to kmp baby!
🙌 1