Hi all, Wondering if we can call API synchronously...
# multiplatform
a
Hi all, Wondering if we can call API synchronously using Ktor Engine. Actually, whenever I'm getting 401 Authorization Token Expired error, I've to call Login API implicitly from Authenticator. Now this api call need to be called synchronously as after getting login API response, i've to update the header with Auth Token and return the request again from authenticate method.
Copy code
Update : I was not aware of ktor-client-auth, let me check if it'll help me.
Thanks
g
I think you want not “syncronous” API for Ktor, you want pause requests until token is authorized,
a
Yes, I've Authenticator, This is what I want to do actually
Copy code
override fun authenticate(route: Route?, response: Response): Request? {
    //refresh Token by calling login api again
    // return request with new updated Token
}
But from this authenticate method, I'm not able to call my suspend login method. As I've to return the request also once I got the response from Login API, So I was wanting to run those calls sequentially.
g
I’m not super familiar with this API, but isn’t you should implement own AuthProvider not Authenticator
a
Sure, I'm looking for various possible ways. Would you please share any resource having AuthProvider if you are aware
a
Ok, thanks
g
maybe existing BearerAuthProvider would work for you too