@@ -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_ ,
@@ -235,6 +238,8 @@ Service_.prototype.handleCallback = function(callbackRequest) {
235
238
} ,
236
239
muteHttpExceptions : true
237
240
} ) ;
241
+ Logger . log ( response . getAllHeaders ( ) ) ;
242
+ Logger . log ( 'Response:' + response . getContentText ( ) ) ;
238
243
var token = this . parseToken_ ( response . getContentText ( ) ) ;
239
244
if ( response . getResponseCode ( ) != 200 ) {
240
245
var reason = token . error ? token . error : response . getResponseCode ( ) ;
@@ -258,7 +263,7 @@ Service_.prototype.hasAccess = function() {
258
263
var expires_in = token . expires_in || token . expires ;
259
264
if ( expires_in ) {
260
265
var expires_time = token . granted_time + expires_in ;
261
- var now = getTimeInSeconds_ ( ) ;
266
+ var now = getTimeInSeconds_ ( new Date ( ) ) ;
262
267
if ( expires_time - now < Service_ . EXPIRATION_BUFFER_SECONDS_ ) {
263
268
if ( token . refresh_token ) {
264
269
this . refresh_ ( ) ;
@@ -317,7 +322,7 @@ Service_.prototype.parseToken_ = function(content) {
317
322
} else {
318
323
throw 'Unknown token format: ' + this . tokenFormat_ ;
319
324
}
320
- token . granted_time = getTimeInSeconds_ ( ) ;
325
+ token . granted_time = getTimeInSeconds_ ( new Date ( ) ) ;
321
326
return token ;
322
327
} ;
323
328
@@ -338,6 +343,9 @@ Service_.prototype.refresh_ = function() {
338
343
}
339
344
var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
340
345
method : 'post' ,
346
+ headers : {
347
+ 'Accept' : this . tokenFormat_
348
+ } ,
341
349
payload : {
342
350
refresh_token : token . refresh_token ,
343
351
client_id : this . clientId_ ,
@@ -410,4 +418,3 @@ Service_.prototype.getToken_ = function() {
410
418
Service_ . prototype . getPropertyKey = function ( serviceName ) {
411
419
return 'oauth2.' + serviceName ;
412
420
} ;
413
-
0 commit comments