Reputation: 5740
I'm using Okhttp3 and I want to build an OAuth2 Authenticator
.
Sometimes, I need to make http requests from the Authenticator itself (ie: to refresh the token) but the api doesn't provide a way to do it.
For sure, I can create a new okhttp instance but I don't know if it is a recommanded practice.
Is it a best practice for my need?
Upvotes: 1
Views: 503
Reputation: 5740
It is not possible to do it out of the box but some workarounds can work:
OkHttpClient
into the Authenticator
, or.
MyAuthenticator authenticator = new MyAuthenticator();
OkHttpClient client = new OkHttpClient.Builder()
.authenticator(authenticator)
.build();
authenticator.setHttpClient(client);
From: https://github.com/square/okhttp/issues/2733
Upvotes: 2