I use Auth0, which gives me JWT (json web token) and refreshtoken. I use this JWT in the http headers to communicate with my backend.
It may happen that the server gives me 403 when it decides that the JWT has expired. In this case, I can ask Auth0 to release me a new JWT using refreshtoken. This means that I call the Auth0 server, pass it a refreshtoken, and it gives me a new JWT, which I can then use in my requests.
My question is, how can I effectively write this behavior in all network code? I will talk with several endpoints, and all of them can return 403.
I think I should first make an interceptor that adds JWT to all requests.
Then there should be a behavior that 403 detects silently making an Auth0 network call, receiving a new JWT. Then the original request should be checked again with the new JWT in its headers.
Therefore, I would prefer this 403 processing to be invisible to my other code, and certainly no need to rewrite it everywhere.
Any pointers on how to achieve this would be appreciated.
-
To be clear, I'm mostly looking for pointers on how to achieve this using RxAndroid Observables. When a specific Observable finds 403, it must βenterβ a new network call.
source share