We use token authentication with our app. Can som...
# ktor
t
We use token authentication with our app. Can somebody point me to an example of how to configure the bearer section so that the auth/refresh token can be shared across more than one http client? We have two different servers (dept1.mycompany.com and dept2.mycompany.com) that use the same auth token.
a
You can create a
BearerAuthProvider
object and add it to a list of providers for both clients. In this case a token holder will be shared so this solution should work in principle:
Copy code
val provider = BearerAuthProvider({
    // refresh token logic
    BearerTokens("", "")
}, {
    // load token logic
    BearerTokens("", "")
}, realm = null)

val client1 = HttpClient(OkHttp) {
    install(Auth) {
        providers.add(provider)
    }
}

val client2 = HttpClient(OkHttp) {
    install(Auth) {
        providers.add(provider)
    }
}
t
This is cool. Thank you!