https://kotlinlang.org logo
#ktor
Title
# ktor
a

Ankit Dubey

03/01/2022, 6:00 AM
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. Thanks
i

ishitatsuyuki

03/01/2022, 6:15 AM
You don't have to call the APIs in a blocking way. Ktor interceptor can take suspend functions, see how AuthProvider does it. https://github.com/ktorio/ktor/blob/b5b59ca3ae61601e6175f334e6a1252609638e61/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt#L39 You also might want to block all other requests until the login is complete (and not send duplicate login requests), see https://github.com/ktorio/ktor/commit/9ea85698bca94113a71c65677ef6a1e1de379a07.
a

Ankit Dubey

03/01/2022, 6:15 AM
Thanks , let me check
2 Views