Hey all, I’m trying to implement the okhttp Authen...
# android
m
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?
😶 1
m
This is the proactive approach. I tried to implement the reactive approach using OkHttp3 Authenticator interface
n
You can use Mutex when accessToken is not refresh 😉
m
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
😮 it’s not a good pratice a singleton for this case
328 Views