Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth Header Bearer Token refresh, AF5 beta #61

Open
n13 opened this issue Mar 24, 2019 · 2 comments
Open

Auth Header Bearer Token refresh, AF5 beta #61

n13 opened this issue Mar 24, 2019 · 2 comments

Comments

@n13
Copy link
Contributor

n13 commented Mar 24, 2019

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.

@n13 n13 changed the title Auth Header Bearer Token refresh on each call Auth Header Bearer Token refresh, AF5 beta Mar 24, 2019
@s4cha
Copy link
Member

s4cha commented Mar 24, 2019

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?

@n13
Copy link
Contributor Author

n13 commented Mar 25, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants