@@ -306,9 +306,11 @@ Service_.prototype.setGrantType = function(grantType) {
306
306
* have the user visit this URL and approve the authorization request. The
307
307
* user will then be redirected back to your application using callback function
308
308
* name specified, so that the flow may continue.
309
+ * @param {Object } optAdditionalParameters Additional parameters that should be
310
+ * stored in the state token and made available in the callback function.
309
311
* @return {string } The authorization URL.
310
312
*/
311
- Service_ . prototype . getAuthorizationUrl = function ( ) {
313
+ Service_ . prototype . getAuthorizationUrl = function ( optAdditionalParameters ) {
312
314
validate_ ( {
313
315
'Client ID' : this . clientId_ ,
314
316
'Script ID' : this . scriptId_ ,
@@ -317,16 +319,20 @@ Service_.prototype.getAuthorizationUrl = function() {
317
319
} ) ;
318
320
319
321
var redirectUri = getRedirectUri ( this . scriptId_ ) ;
320
- var state = eval ( 'Script' + 'App' ) . newStateToken ( )
322
+ var stateTokenBuilder = eval ( 'Script' + 'App' ) . newStateToken ( )
321
323
. withMethod ( this . callbackFunctionName_ )
322
324
. withArgument ( 'serviceName' , this . serviceName_ )
323
- . withTimeout ( 3600 )
324
- . createToken ( ) ;
325
+ . withTimeout ( 3600 ) ;
326
+ if ( optAdditionalParameters ) {
327
+ Object . keys ( optAdditionalParameters ) . forEach ( function ( key ) {
328
+ stateTokenBuilder . withArgument ( key , optAdditionalParameters [ key ] ) ;
329
+ } ) ;
330
+ }
325
331
var params = {
326
332
client_id : this . clientId_ ,
327
333
response_type : 'code' ,
328
334
redirect_uri : redirectUri ,
329
- state : state
335
+ state : stateTokenBuilder . createToken ( )
330
336
} ;
331
337
params = extend_ ( params , this . params_ ) ;
332
338
return buildUrl_ ( this . authorizationBaseUrl_ , params ) ;
0 commit comments