@@ -34,6 +34,15 @@ var TOKEN_FORMAT = {
3434 FORM_URL_ENCODED : 'application/x-www-form-urlencoded'
3535} ;
3636
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+
3746/**
3847 * Creates a new OAuth2 service with the name specified. It's usually best to create and
3948 * configure your service once at the start of your script, and then reference them during
@@ -48,19 +57,12 @@ function createService(serviceName) {
4857/**
4958 * Returns the redirect URI that will be used for a given script. Often this URI
5059 * 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
5261 * the Script Editor UI under "File > Project properties".
5362 * @return {string } The redirect URI.
5463 */
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 ) ;
6466}
6567
6668// Copyright 2014 Google Inc. All Rights Reserved.
@@ -98,7 +100,7 @@ var Service_ = function(serviceName) {
98100 this . params_ = { } ;
99101 this . tokenFormat_ = TOKEN_FORMAT . JSON ;
100102 this . tokenHeaders_ = null ;
101- this . projectKey_ = eval ( 'Script' + 'App' ) . getProjectKey ( ) ;
103+ this . scriptId_ = eval ( 'Script' + 'App' ) . getScriptId ( ) ;
102104 this . expirationMinutes_ = 60 ;
103105} ;
104106
@@ -162,18 +164,6 @@ Service_.prototype.setTokenPayloadHandler = function(tokenHandler) {
162164 return this ;
163165} ;
164166
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-
177167/**
178168 * Sets the name of the authorization callback function (required). This is the function that will be
179169 * called when the user completes the authorization flow on the service provider's website.
@@ -310,19 +300,19 @@ Service_.prototype.setExpirationMinutes = function(expirationMinutes) {
310300/**
311301 * Gets the authorization URL. The first step in getting an OAuth2 token is to
312302 * 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.
315305 * @returns {string } The authorization URL.
316306 */
317307Service_ . prototype . getAuthorizationUrl = function ( ) {
318308 validate_ ( {
319309 'Client ID' : this . clientId_ ,
320- 'Project key ' : this . projectKey_ ,
310+ 'Script ID ' : this . scriptId_ ,
321311 'Callback function name' : this . callbackFunctionName_ ,
322312 'Authorization base URL' : this . authorizationBaseUrl_
323313 } ) ;
324314
325- var redirectUri = this . getRedirectUri ( ) ;
315+ var redirectUri = getRedirectUri ( this . scriptId_ ) ;
326316 var state = eval ( 'Script' + 'App' ) . newStateToken ( )
327317 . withMethod ( this . callbackFunctionName_ )
328318 . withArgument ( 'serviceName' , this . serviceName_ )
@@ -356,10 +346,10 @@ Service_.prototype.handleCallback = function(callbackRequest) {
356346 validate_ ( {
357347 'Client ID' : this . clientId_ ,
358348 'Client Secret' : this . clientSecret_ ,
359- 'Project key ' : this . projectKey_ ,
349+ 'Script ID ' : this . scriptId_ ,
360350 'Token URL' : this . tokenUrl_
361351 } ) ;
362- var redirectUri = this . getRedirectUri ( ) ;
352+ var redirectUri = getRedirectUri ( this . scriptId_ ) ;
363353 var headers = {
364354 'Accept' : this . tokenFormat_
365355 } ;
@@ -457,7 +447,7 @@ Service_.prototype.getLastError = function() {
457447 * @return {Exception } An error, if any.
458448 */
459449Service_ . prototype . getRedirectUri = function ( ) {
460- return getRedirectUri ( this . projectKey_ ) ;
450+ return getRedirectUri ( this . scriptId_ ) ;
461451} ;
462452
463453/**
0 commit comments