When the client deems a token to have expired, using its locally stored creation time and expires_in values, it will automatically renew the token. The renewed token can then be stored/persisted by the application using the callback provided in #110 That works great, and takes the renewal burden away from the business logic of the application.
Now, the locally stored expiry time may be out of step from the real expiry time. This is especially the case at the edge of the token lifetime where HTTP delays in the fetching of the original token may put he expiry time out by one second or more, leaving the application thinking the token has a second more of life, but Google insisting the expired a second ago. This results in an exception, right in the middle of the business logic using the API.
This exception can be caught, the message checked, a token renewal attempted etc and that can get things back on track. However, that is not a domain that should impinge on the business side of the application; it really does not care about the OAuth negotiating wranglings, and it really should not have to care.
So, what I would like to propose for discussion, is a callback that can be used in a similar way to the expired token callback, to allow the application to invisibly attempt to fix any token issues in the event of an invalid token being found. I guess this callback would replace the exception once, then the client would reattempt the remote API call. If it works, great, all carries on happily. If it does not work, then fine, the application had a chance to fix its tokens but couldn't.
Issues I see are the recursive nature of this callback: the callback to the client trying to access the API would need to use the same client to renew the tokens. That may or may not have side-effects.
My workaround at the moment, to try to steer away from this edge-case, is to knock five minutes off the expires_in that the client supplies for a new token, so it renews early. But that's not ideal. This is all in the interest of keeping the lights on in offline access to the API when OAuth authenticated by an end user.
When the client deems a token to have expired, using its locally stored creation time and expires_in values, it will automatically renew the token. The renewed token can then be stored/persisted by the application using the callback provided in #110 That works great, and takes the renewal burden away from the business logic of the application.
Now, the locally stored expiry time may be out of step from the real expiry time. This is especially the case at the edge of the token lifetime where HTTP delays in the fetching of the original token may put he expiry time out by one second or more, leaving the application thinking the token has a second more of life, but Google insisting the expired a second ago. This results in an exception, right in the middle of the business logic using the API.
This exception can be caught, the message checked, a token renewal attempted etc and that can get things back on track. However, that is not a domain that should impinge on the business side of the application; it really does not care about the OAuth negotiating wranglings, and it really should not have to care.
So, what I would like to propose for discussion, is a callback that can be used in a similar way to the expired token callback, to allow the application to invisibly attempt to fix any token issues in the event of an invalid token being found. I guess this callback would replace the exception once, then the client would reattempt the remote API call. If it works, great, all carries on happily. If it does not work, then fine, the application had a chance to fix its tokens but couldn't.
Issues I see are the recursive nature of this callback: the callback to the client trying to access the API would need to use the same client to renew the tokens. That may or may not have side-effects.
My workaround at the moment, to try to steer away from this edge-case, is to knock five minutes off the expires_in that the client supplies for a new token, so it renews early. But that's not ideal. This is all in the interest of keeping the lights on in offline access to the API when OAuth authenticated by an end user.