Issue
I am using Ktor client for Android together with the plugin: io.ktor:ktor-client-auth:1.6.4
. The current implementation is similar to this snippet.
Now I want to implement a 'log out' function when after a button is clicked the tokens are deleted, the question is... how?
Solution
You can get an instance of the Auth
plugin, find a BearerAuthProvider
provider and call the clearToken
method to delete tokens. Here is an example:
val client = HttpClient(Apache) {
install(Auth) {
bearer {}
}
}
val provider = client.feature(Auth)!!.providers.filterIsInstance<BearerAuthProvider>().first()
provider.clearToken()
Answered By - Aleksei Tirman