Refresh before request if neccesary and multipart only when resource and media body specified#235
Merged
ryanseys merged 7 commits intogoogleapis:masterfrom Jul 30, 2014
ryanseys:refresh-before
Merged
Refresh before request if neccesary and multipart only when resource and media body specified#235ryanseys merged 7 commits intogoogleapis:masterfrom ryanseys:refresh-before
ryanseys merged 7 commits intogoogleapis:masterfrom
ryanseys:refresh-before
Conversation
Contributor
Author
|
Also #122. |
lib/auth/jwtclient.js
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Contributor
|
Media upload changes LGTM, commented on a few issues about auth related changes. |
ryanseys
added a commit
that referenced
this pull request
Jul 30, 2014
Refresh before request if neccesary and multipart only when resource and media body specified
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently when we make an API request and the request responds with an authentication error, we attempt to refresh the
access_tokenusing therefresh_tokenand 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:expiry_date(an added property) of the credentials object to ensure that the token has not expired. If there is noexpiry_datevalue, assume it has not expired. If it has expired, refresh the token before making the request.access_tokenin the credentials, and there is arefresh_token, use it to refresh the token before making the request.refresh_token, never attempt to refresh (because you can't)access_tokennorrefresh_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.
Also added
oauth2client.revokeCredentials()which will clear the credentials object and attempt to revoke theaccess_token.Bonus: Affects #229 where multipart request was built for all media requests. Now multipart will only be built for requests with
resourceandmedia.body. Ifresourceis only specified, it's a simple JSON request, if onlymedia.bodyis specified, then uploadType=media is used with the body (not a multipart).