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

darkmoon_uk

11/01/2021, 3:22 AM
When we want to use Ktor Client to access endpoints with or without authentication; is it expected we'll keep both 'authenticated' and 'unauthenticated'
HttpClient
instances on hand, and pick one? Or, is there a lighter way to opt to use the installed authentication, or not, per call?
not sure if you’re able to override that method
a

Aleksei Tirman [JB]

11/01/2021, 12:16 PM
@darkmoon_uk unfortunately, no.
d

darkmoon_uk

11/01/2021, 12:24 PM
Thanks. I've currently settled for having both an 'authenticated' client and an 'unauthenticated' client. The thing that tipped me further towards that was; if you want to 'log out' there's no way to clear the keys loaded into JWT authentication, the only way to effectively and reliably drop them seems to be switching client. Ended up injecting a 'provideClient' lambda to my services which gives either the authenticated or unauthenticated client depending on the session state (login/out). No idea if this is idiomatic but it works for me.
3 Views