-
Notifications
You must be signed in to change notification settings - Fork 345
Add support to refresh the token on expiry #12
Comments
There are two ways to use AFOAuth2Client currently. The first is to subclass from In addition to that hurdle, there are many practical issues with the implementation of auto-refresh. The first is that there is no reliable, global position to check for token expiry. There is no reliable way to intercept all operations being added to the operation queue, and there is no way to run code before each operation runs. There is KVO, but KVO is not meant for writing code to intervene, but rather, to observe. It is possible to intercept all operations as they are created, but that is at a disconnect with when the operation would actually run, which is an important factor when dealing with expiration. On top of that, if you determine that an operation is about to run, about to send a request with an expired token, what do you do? You can halt the operation and refresh the token, but now what? You would need a way of injecting the new token into the request of the pending operation(s), something that is not possible with the current API. I managed to do it here, but that implementation has its share of hackery.. |
I am currently confronted with this issue and thinking about extending I will let you know how that works out for me and maybe pull-request it in if the code is good enough. |
As you can see from my recent pull-requests, I found a way to implement this. Alas, it requires some significant changes to the original code. I do, however, believe that those changes make using the client easier, even if automatic refreshing is not pulled in. |
To close the loop on this, the best solution I've found for dealing with this is to use dependent |
Currently if the token expires - no check is made before to make sure the token is not expired.
It should check for expiration before making the request - if expired - use refresh token to get a fresh access token.
The text was updated successfully, but these errors were encountered: