@@ -60,8 +60,8 @@ Service_.prototype.setTokenUrl = function(tokenUrl) {
60
60
} ;
61
61
62
62
/**
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.
65
65
* @return {Service_ } This service, for chaining.
66
66
*/
67
67
Service_ . prototype . setTokenFormat = function ( tokenFormat ) {
@@ -226,6 +226,9 @@ Service_.prototype.handleCallback = function(callbackRequest) {
226
226
var redirectUri = getRedirectUri ( this . projectKey_ ) ;
227
227
var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
228
228
method : 'post' ,
229
+ headers : {
230
+ 'Accept' : this . tokenFormat_
231
+ } ,
229
232
payload : {
230
233
code : code ,
231
234
client_id : this . clientId_ ,
@@ -258,7 +261,7 @@ Service_.prototype.hasAccess = function() {
258
261
var expires_in = token . expires_in || token . expires ;
259
262
if ( expires_in ) {
260
263
var expires_time = token . granted_time + expires_in ;
261
- var now = getTimeInSeconds_ ( ) ;
264
+ var now = getTimeInSeconds_ ( new Date ( ) ) ;
262
265
if ( expires_time - now < Service_ . EXPIRATION_BUFFER_SECONDS_ ) {
263
266
if ( token . refresh_token ) {
264
267
this . refresh_ ( ) ;
@@ -317,7 +320,7 @@ Service_.prototype.parseToken_ = function(content) {
317
320
} else {
318
321
throw 'Unknown token format: ' + this . tokenFormat_ ;
319
322
}
320
- token . granted_time = getTimeInSeconds_ ( ) ;
323
+ token . granted_time = getTimeInSeconds_ ( new Date ( ) ) ;
321
324
return token ;
322
325
} ;
323
326
@@ -338,6 +341,9 @@ Service_.prototype.refresh_ = function() {
338
341
}
339
342
var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
340
343
method : 'post' ,
344
+ headers : {
345
+ 'Accept' : this . tokenFormat_
346
+ } ,
341
347
payload : {
342
348
refresh_token : token . refresh_token ,
343
349
client_id : this . clientId_ ,
@@ -410,4 +416,3 @@ Service_.prototype.getToken_ = function() {
410
416
Service_ . prototype . getPropertyKey = function ( serviceName ) {
411
417
return 'oauth2.' + serviceName ;
412
418
} ;
413
-
0 commit comments