google/google-api-nodejs-client — pull request #235 by ryanseys (2014-07-29 16:09:05+00:00)
Title: Refresh before request if neccesary

Currently when we make an API request and the request responds with an authentication error, we attempt to refresh the `access_token` using the `refresh_token` and then re-attempt the request. If the request has a multipart body, it will not be attached to the re-attempted request due to the constraints of the library. This is exceptionally true for multipart bodies whose data is coming from a readable stream. To mitigate these issues, this PR makes the following changes:
- Check `expiry_date` (an added property) of the credentials object to ensure that the token has not expired. If there is no `expiry_date` value, assume it has not expired. If it has expired, refresh the token before making the request.
- If there is no `access_token` in the credentials, and there is a `refresh_token`, use it to refresh the token before making the request.
- If there is no `refresh_token`, never attempt to refresh (because you can't)
- If you have no `access_token` or `refresh_token`, return an error in the callback.

This will give more responsibility to the developer to ensure that their credentials are kept up to date.