@@ -34,6 +34,15 @@ var TOKEN_FORMAT = {
34
34
FORM_URL_ENCODED : 'application/x-www-form-urlencoded'
35
35
} ;
36
36
37
+ /**
38
+ * The supported locations for passing the state parameter.
39
+ * @type {Object.<string, string> }
40
+ */
41
+ var STATE_PARAMETER_LOCATION = {
42
+ AUTHORIZATION_URL : 'authorization-url' ,
43
+ REDIRECT_URL : 'redirect-url'
44
+ } ;
45
+
37
46
/**
38
47
* Creates a new OAuth2 service with the name specified. It's usually best to create and
39
48
* configure your service once at the start of your script, and then reference them during
@@ -48,19 +57,12 @@ function createService(serviceName) {
48
57
/**
49
58
* Returns the redirect URI that will be used for a given script. Often this URI
50
59
* needs to be entered into a configuration screen of your OAuth provider.
51
- * @param {string } projectKey The project key of your script, which can be found in
60
+ * @param {string } scriptID The script ID of your script, which can be found in
52
61
* the Script Editor UI under "File > Project properties".
53
62
* @return {string } The redirect URI.
54
63
*/
55
- function getRedirectUri ( projectKey ) {
56
- return Utilities . formatString ( 'https://script.google.com/macros/d/%s/usercallback' , projectKey ) ;
57
- }
58
-
59
- if ( module ) {
60
- module . exports = {
61
- createService : createService ,
62
- getRedirectUri : getRedirectUri
63
- } ;
64
+ function getRedirectUri ( scriptId ) {
65
+ return Utilities . formatString ( 'https://script.google.com/macros/d/%s/usercallback' , scriptId ) ;
64
66
}
65
67
66
68
// Copyright 2014 Google Inc. All Rights Reserved.
@@ -98,7 +100,7 @@ var Service_ = function(serviceName) {
98
100
this . params_ = { } ;
99
101
this . tokenFormat_ = TOKEN_FORMAT . JSON ;
100
102
this . tokenHeaders_ = null ;
101
- this . projectKey_ = eval ( 'Script' + 'App' ) . getProjectKey ( ) ;
103
+ this . scriptId_ = eval ( 'Script' + 'App' ) . getScriptId ( ) ;
102
104
this . expirationMinutes_ = 60 ;
103
105
} ;
104
106
@@ -162,18 +164,6 @@ Service_.prototype.setTokenPayloadHandler = function(tokenHandler) {
162
164
return this ;
163
165
} ;
164
166
165
- /**
166
- * Sets the project key of the script that contains the authorization callback function (required).
167
- * The project key can be found in the Script Editor UI under "File > Project properties".
168
- * @param {string } projectKey The project key of the project containing the callback function.
169
- * @return {Service_ } This service, for chaining.
170
- * @deprecated The project key is now be determined automatically.
171
- */
172
- Service_ . prototype . setProjectKey = function ( projectKey ) {
173
- this . projectKey_ = projectKey ;
174
- return this ;
175
- } ;
176
-
177
167
/**
178
168
* Sets the name of the authorization callback function (required). This is the function that will be
179
169
* called when the user completes the authorization flow on the service provider's website.
@@ -310,19 +300,19 @@ Service_.prototype.setExpirationMinutes = function(expirationMinutes) {
310
300
/**
311
301
* Gets the authorization URL. The first step in getting an OAuth2 token is to
312
302
* have the user visit this URL and approve the authorization request. The
313
- * user will then be redirected back to your application using the
314
- * project key and callback function name specified, so that the flow may continue.
303
+ * user will then be redirected back to your application using callback function
304
+ * name specified, so that the flow may continue.
315
305
* @returns {string } The authorization URL.
316
306
*/
317
307
Service_ . prototype . getAuthorizationUrl = function ( ) {
318
308
validate_ ( {
319
309
'Client ID' : this . clientId_ ,
320
- 'Project key ' : this . projectKey_ ,
310
+ 'Script ID ' : this . scriptId_ ,
321
311
'Callback function name' : this . callbackFunctionName_ ,
322
312
'Authorization base URL' : this . authorizationBaseUrl_
323
313
} ) ;
324
314
325
- var redirectUri = this . getRedirectUri ( ) ;
315
+ var redirectUri = getRedirectUri ( this . scriptId_ ) ;
326
316
var state = eval ( 'Script' + 'App' ) . newStateToken ( )
327
317
. withMethod ( this . callbackFunctionName_ )
328
318
. withArgument ( 'serviceName' , this . serviceName_ )
@@ -356,10 +346,10 @@ Service_.prototype.handleCallback = function(callbackRequest) {
356
346
validate_ ( {
357
347
'Client ID' : this . clientId_ ,
358
348
'Client Secret' : this . clientSecret_ ,
359
- 'Project key ' : this . projectKey_ ,
349
+ 'Script ID ' : this . scriptId_ ,
360
350
'Token URL' : this . tokenUrl_
361
351
} ) ;
362
- var redirectUri = this . getRedirectUri ( ) ;
352
+ var redirectUri = getRedirectUri ( this . scriptId_ ) ;
363
353
var headers = {
364
354
'Accept' : this . tokenFormat_
365
355
} ;
@@ -457,7 +447,7 @@ Service_.prototype.getLastError = function() {
457
447
* @return {Exception } An error, if any.
458
448
*/
459
449
Service_ . prototype . getRedirectUri = function ( ) {
460
- return getRedirectUri ( this . projectKey_ ) ;
450
+ return getRedirectUri ( this . scriptId_ ) ;
461
451
} ;
462
452
463
453
/**
0 commit comments