Auth Header Bearer Token refresh, AF5 beta
Before each call, I need to check if my bearer token is still OK, and if not get a new one, and then set it in the headers.
I looked into the code, it will be trivial to add a RequestAdapter to ws - as supported by Alamofire 4 - and that could do that except not asynchronously. So I'd still get occasional errors when the token isn't refreshed in time. And I'd have to deal with those errors on a code level which kind of destroys the elegance and simplicity of using ws.
AlamoFire 5 has a built in solution for this exact problem.
I have two questions
-
Has anybody looked into upgrading to AlamoFire 5 (currently in beta)? That would allow for asynchronous bearer token refresh, making what I need trivial to implement. They added a callback to RequestAdapter - super easy to use.
-
Is there another good way you can think of to provide a feature similar to AF5 callback based RequestAdapter? Didn't really see one...
As ws library is concerned upgrading to AF5 is probably the best way to go about it.
Hi @n13 Thanks a ton for reporting this ! According to you research, I think upgrading to Alamofire 5 seems reasonable. I haven't looked into it yet. I have very small time to work on this at the moment, would you be willing to give it a shot in a Pull Request?
Happy to provide a PR for you that supports the already existing RequestAdapter- I am using this now for this purpose and thinking apart from edge cases, it's good enough for me.
Firebase auth has a listener to token changes so once I have a valid token, I can rely on the listener to update when necessary. Which leaves the edge cases of app start and awake from sleep which I am dealing with.
RequestAdapter support is a very small change.
Thanks for making ws, I love it.