Hooking MSAL into OkHttp's Interceptors
See original GitHub issueIs your feature request related to a problem? Please describe.
I’d like to be able to fetch the MSAL auth token synchronously, so I can hook the authentication mechanism into OkHttp through an Interceptor.
Right now, on my app, all my repositories inherit from a BaseRepository
, this BaseRepository
has a function named fetchMsalToken()
. This fetchMsalToken()
function runs the aquireTokenSilentAsync()
through RxJava. Thanks to that I can flat map this function before calling any of my endpoints, so I can be sure that I’m refreshing the auth token before each call to the backend.
Ideally, I’d like to do all this within an Interceptor, somehow run the aquireTokenSilentAsync()
synchronously, and set the auth token on the headers of the request.
Describe the solution you’d like
Is it there any way to run the aquireTokenSilentAsync()
synchronously within an Interceptor, so I can refresh the auth token there and keep any code related to this, out of my repositories.
Describe alternatives you’ve considered
As I mentioned, what I’ve done so far it’s creating a RxJava function that runs the aquireTokenSilentAsync()
, and using RxJava’s flatmap function, I hook that into my API calls.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Thanks for the quick response @iambmelt ! 🙌 Okay, cool, I’m going to try to handle things from my side then, with that “patch”. It’d be nice having the library handle these things though, the library works fine but as soon as you start trying to plug the library into some other technologies (Dagger, Retrofit) things start to work a bit funny. I get that it is equally difficult to handle these things on the library or in the client app, but maybe it would be useful introducing something like a BaseApplication class from which we could extend that guarantees that we always have an access token available. Thanks again!
I am getting the same error but only in combination with MS Authenticator. We are trying to make a plugin to get MSAL working with Ionic 5/ Capacitor.