@@ -28,6 +28,7 @@ var Service_ = function(serviceName) {
28
28
this . serviceName_ = serviceName ;
29
29
this . params_ = { } ;
30
30
this . tokenFormat_ = TOKEN_FORMAT . JSON ;
31
+ this . tokenHeaders_ = null ;
31
32
} ;
32
33
33
34
/**
@@ -69,6 +70,17 @@ Service_.prototype.setTokenFormat = function(tokenFormat) {
69
70
return this ;
70
71
} ;
71
72
73
+ /**
74
+ * Sets the additional HTTP headers that should be sent when retrieving or
75
+ * refreshing the access token.
76
+ * @param Object.<string,string> tokenHeaders A map of header names to values.
77
+ * @return {Service_ } This service, for chaining.
78
+ */
79
+ Service_ . prototype . setTokenHeaders = function ( tokenHeaders ) {
80
+ this . tokenHeaders_ = tokenHeaders ;
81
+ return this ;
82
+ } ;
83
+
72
84
/**
73
85
* Sets the project key of the script that contains the authorization callback function (required).
74
86
* The project key can be found in the Script Editor UI under "File > Project properties".
@@ -224,11 +236,15 @@ Service_.prototype.handleCallback = function(callbackRequest) {
224
236
'Token URL' : this . tokenUrl_
225
237
} ) ;
226
238
var redirectUri = getRedirectUri ( this . projectKey_ ) ;
239
+ var headers = {
240
+ 'Accept' : this . tokenFormat_
241
+ } ;
242
+ if ( this . tokenHeaders_ ) {
243
+ headers = _ . extend ( headers , this . tokenHeaders_ ) ;
244
+ }
227
245
var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
228
246
method : 'post' ,
229
- headers : {
230
- 'Accept' : this . tokenFormat_
231
- } ,
247
+ headers : headers ,
232
248
payload : {
233
249
code : code ,
234
250
client_id : this . clientId_ ,
@@ -338,11 +354,15 @@ Service_.prototype.refresh = function() {
338
354
if ( ! token . refresh_token ) {
339
355
throw 'Offline access is required.' ;
340
356
}
357
+ var headers = {
358
+ 'Accept' : this . tokenFormat_
359
+ } ;
360
+ if ( this . tokenHeaders_ ) {
361
+ headers = _ . extend ( headers , this . tokenHeaders_ ) ;
362
+ }
341
363
var response = UrlFetchApp . fetch ( this . tokenUrl_ , {
342
364
method : 'post' ,
343
- headers : {
344
- 'Accept' : this . tokenFormat_
345
- } ,
365
+ headers : headers ,
346
366
payload : {
347
367
refresh_token : token . refresh_token ,
348
368
client_id : this . clientId_ ,
0 commit comments