@@ -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 . stateParameterLocation_ = STATE_PARAMETER_LOCATION . AUTHORIZATION_URL ;
31
32
} ;
32
33
33
34
/**
@@ -69,6 +70,18 @@ Service_.prototype.setTokenFormat = function(tokenFormat) {
69
70
return this ;
70
71
} ;
71
72
73
+ /**
74
+ * Sets the location of the state parameter, which is required by the
75
+ * /usercallback endpoint.
76
+ * Default: OAuth2.STATE_PARAMETER_LOCATION.AUTHORIZATION_URL.
77
+ * @param {STATE_PARAMETER_LOCATION } tokenFormat The format of the returned token.
78
+ * @return {Service_ } This service, for chaining.
79
+ */
80
+ Service_ . prototype . setStateParameterLocation = function ( stateParameterLocation ) {
81
+ this . stateParameterLocation_ = stateParameterLocation
82
+ return this ;
83
+ } ;
84
+
72
85
/**
73
86
* Sets the project key of the script that contains the authorization callback function (required).
74
87
* The project key can be found in the Script Editor UI under "File > Project properties".
@@ -194,10 +207,16 @@ Service_.prototype.getAuthorizationUrl = function() {
194
207
. createToken ( ) ;
195
208
var params = {
196
209
client_id : this . clientId_ ,
197
- response_type : 'code' ,
198
- redirect_uri : redirectUri ,
199
- state : state
210
+ response_type : 'code'
200
211
} ;
212
+ if ( this . stateParameterLocation_ == STATE_PARAMETER_LOCATION . AUTHORIZATION_URL ) {
213
+ params [ 'state' ] = state ;
214
+ } else {
215
+ redirectUri = buildUrl_ ( redirectUri , {
216
+ state : state
217
+ } ) ;
218
+ }
219
+ params [ 'redirect_uri' ] = redirectUri ;
201
220
params = _ . extend ( params , this . params_ ) ;
202
221
return buildUrl_ ( this . authorizationBaseUrl_ , params ) ;
203
222
} ;
@@ -327,9 +346,8 @@ Service_.prototype.parseToken_ = function(content) {
327
346
/**
328
347
* Refreshes a token that has expired. This is only possible if offline access was
329
348
* requested when the token was authorized.
330
- * @private
331
349
*/
332
- Service_ . prototype . refresh_ = function ( ) {
350
+ Service_ . prototype . refresh = function ( ) {
333
351
validate_ ( {
334
352
'Client ID' : this . clientId_ ,
335
353
'Client Secret' : this . clientSecret_ ,
0 commit comments