I think <https://square.github.io/okhttp/4.x/okhtt...
# squarelibraries
e
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
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)?
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
you can do preemptive + reauth from a single interceptor
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
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.