Hey all,
I’m trying to implement the okhttp Authenticator to re-authenticate upon access token expiration (401).
My question is how to handle when multiple networks calls are sent and return with 401.
I tried to annotate the function with @Syncrornized in order to call the remote refresh token API only once instead of for each of the bounced 401 calls.
the annotation doesn’t work and i see in the logs that the function that is annotated with it still being called more than once at given time.
any suggestion/help?
This is the proactive approach.
I tried to implement the reactive approach using OkHttp3 Authenticator interface
n
Nicolas B
06/09/2022, 12:56 PM
You can use Mutex when accessToken is not refresh 😉
m
Mark Lurie
06/21/2022, 6:44 AM
Solved it, my problem with @Syncronized was i injected the TokenAuthenticator and it was always a different instance, fixed it by annotating it with @Singlton
n
Nicolas B
06/21/2022, 6:49 AM
😮 it’s not a good pratice a singleton for this case