Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding it as an OkHttp interceptor, breaks okhttp3.Authenticator #11

Closed
marius-bardan opened this issue Dec 9, 2022 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@marius-bardan
Copy link

marius-bardan commented Dec 9, 2022

OkHttpClient.Builder builder = new OkHttpClient.Builder()
  .authenticator(authenticator)
  .addInterceptor(cronetInterceptor);

OkHttpClient client = builder.build();

If OkHttpClient is created as per above and request returns with 401 (Unauthorized), then the passed okhttp3.Authenticator is no longer invoked, since that's basically implemented as an interceptor (RetryAndFollowUpInterceptor) added after the cronet interceptor is set (i.e. when the request is executed), as it can be seen in the attached screenshot.

Due to this, the user session won't be refreshed.

image

@Danstahrg
Copy link
Contributor

This is an unfortunate known limitation of OkHttp interceptors: https://github.com/google/cronet-transport-for-okhttp#common-incompatibilities, and there's not much we can do about it from this library's standpoint. The only alternative approach I'm aware of would be to add the Cronet interceptor as a network interceptor but those are handled after after OkHttp's connection level logic (e.g. establishing and pooling connections) so it comes with its own drawbacks.

The existence of this library uncovered some limitations which are being addressed (square/okhttp#7164) so there's hope to address this properly, but realistically I won't have time to start any actual work before the end of the year.

@marius-bardan
Copy link
Author

Maybe it might prove useful to also state this in the Readme page (i.e. that the OkHttp 'authenticator' will also get bypassed).

The entirety of OkHttp core is bypassed. This includes caching, retries, and network interceptors. These features have to be enabled directly on the Cronet engine or built on top of this library.

@Danstahrg Danstahrg added the enhancement New feature or request label Dec 20, 2022
copybara-service bot pushed a commit that referenced this issue Dec 20, 2022
…) features.

Related to #11.

PiperOrigin-RevId: 496598672
@Danstahrg
Copy link
Contributor

That surely doesn't hurt, done.

@marius-bardan marius-bardan closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants