I'm using Bearer Token auth with the ktor client, ...
# ktor
a
I'm using Bearer Token auth with the ktor client, but cant quite figure this out: when i login in and get my new token i save it to storage. but the
HttpClient
it's self doesn't know it needs to call it's
loadTokens
again, is there anyway to get it to reload it's tokens after a login?
🦻 1
o
I went for something like that
Copy code
fun HttpClient.updateCredentials(credentials: Credentials) {
    val authPlugin = plugin(Auth)
    authPlugin.providers.removeAll { true }
    when (credentials) {
        is Credentials.Token -> authPlugin.bearer {
            loadTokens {
                credentials.bearerTokens
            }
        }

        is Credentials.Basic -> authPlugin.basic {
            credentials.basicAuthCredentials
        }
    }
}
I have an extension to convert my
Credentials
to proper ktor version (
BasicAuthCredentials
and
BearerTokens
)
a
oh perfect, just what i was looking for!
106 Views