@@ -60,8 +60,8 @@ Service_.prototype.setTokenUrl = function(tokenUrl) {
6060} ;
6161
6262/**
63- * Sets the format of the returned token. Default: Service_ .TOKEN_FORMAT.JSON.
64- * @param {TOKEN_FORMAT } tokenFormat The format of the returned token.
63+ * Sets the format of the returned token. Default: OAuth2 .TOKEN_FORMAT.JSON.
64+ * @param {OAuth2. TOKEN_FORMAT } tokenFormat The format of the returned token.
6565 * @return {Service_ } This service, for chaining.
6666 */
6767Service_ . prototype . setTokenFormat = function ( tokenFormat ) {
@@ -226,6 +226,9 @@ Service_.prototype.handleCallback = function(callbackRequest) {
226226 var redirectUri = getRedirectUri ( this . projectKey_ ) ;
227227 var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
228228 method : 'post' ,
229+ headers : {
230+ 'Accept' : this . tokenFormat_
231+ } ,
229232 payload : {
230233 code : code ,
231234 client_id : this . clientId_ ,
@@ -258,7 +261,7 @@ Service_.prototype.hasAccess = function() {
258261 var expires_in = token . expires_in || token . expires ;
259262 if ( expires_in ) {
260263 var expires_time = token . granted_time + expires_in ;
261- var now = getTimeInSeconds_ ( ) ;
264+ var now = getTimeInSeconds_ ( new Date ( ) ) ;
262265 if ( expires_time - now < Service_ . EXPIRATION_BUFFER_SECONDS_ ) {
263266 if ( token . refresh_token ) {
264267 this . refresh_ ( ) ;
@@ -317,7 +320,7 @@ Service_.prototype.parseToken_ = function(content) {
317320 } else {
318321 throw 'Unknown token format: ' + this . tokenFormat_ ;
319322 }
320- token . granted_time = getTimeInSeconds_ ( ) ;
323+ token . granted_time = getTimeInSeconds_ ( new Date ( ) ) ;
321324 return token ;
322325} ;
323326
@@ -338,6 +341,9 @@ Service_.prototype.refresh_ = function() {
338341 }
339342 var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
340343 method : 'post' ,
344+ headers : {
345+ 'Accept' : this . tokenFormat_
346+ } ,
341347 payload : {
342348 refresh_token : token . refresh_token ,
343349 client_id : this . clientId_ ,
@@ -410,4 +416,3 @@ Service_.prototype.getToken_ = function() {
410416Service_ . prototype . getPropertyKey = function ( serviceName ) {
411417 return 'oauth2.' + serviceName ;
412418} ;
413-
0 commit comments