I think https://square.github.io/okhttp/4.x/okhttp/okhttp3/-authenticator/ describes it well enough. for pre-emptive proxy auth, null continues with original request. for reactive auth, the original request was already made and came back with a unauthorized response; null makes that the final response instead of making a follow-up request
👍 1
l
Lukasz Kalnik
03/23/2022, 3:18 PM
Thank you for your answer!
Can I also use pre-emptive auth when I don't use a proxy server?
Seems a bit wasteful to always wait for the 401 response to authorize, especially when authorization is always required.
Or should I achieve it through a combination of an
Interceptor
(for pre-emptively authenticating every regular request) and
Authenticator
(e.g. only for cases when I receive 401 because access token has expired and needs to be refreshed)?
Lukasz Kalnik
03/23/2022, 3:38 PM
My use case is that I need to authenticate every request using a bearer token but from time to time the access token expires and I get a 401 response.
Then I want to get a new access token from the OAuth provider using stored refresh token and retry the last call with the new token.
e
ephemient
03/23/2022, 5:25 PM
you can do preemptive + reauth from a single interceptor
ephemient
03/23/2022, 5:26 PM
as long as it's installed as an application interceptor and not a network interceptor, you can proceed with the request chain any number of times
l
Lukasz Kalnik
03/24/2022, 8:50 AM
Ah, ok, that's good to know. Thank you 🙏
For now I went the route:
Interceptor
for preemptive and
Authenticator
for reauth (because of automatic retry). I'll see how it works.