@@ -123,7 +123,7 @@ Service_.LOCK_EXPIRATION_MILLISECONDS_ = 30 * 1000;
123
123
* this URL should be
124
124
* https://accounts.google.com/o/oauth2/auth.
125
125
* @param {string } authorizationBaseUrl The authorization endpoint base URL.
126
- * @return {Service_ } This service, for chaining.
126
+ * @return {! Service_ } This service, for chaining.
127
127
*/
128
128
Service_ . prototype . setAuthorizationBaseUrl = function ( authorizationBaseUrl ) {
129
129
this . authorizationBaseUrl_ = authorizationBaseUrl ;
@@ -134,7 +134,7 @@ Service_.prototype.setAuthorizationBaseUrl = function(authorizationBaseUrl) {
134
134
* Sets the service's token URL (required). For Google services this URL should
135
135
* be https://accounts.google.com/o/oauth2/token.
136
136
* @param {string } tokenUrl The token endpoint URL.
137
- * @return {Service_ } This service, for chaining.
137
+ * @return {! Service_ } This service, for chaining.
138
138
*/
139
139
Service_ . prototype . setTokenUrl = function ( tokenUrl ) {
140
140
this . tokenUrl_ = tokenUrl ;
@@ -145,7 +145,7 @@ Service_.prototype.setTokenUrl = function(tokenUrl) {
145
145
* Sets the service's refresh URL. Some OAuth providers require a different URL
146
146
* to be used when generating access tokens from a refresh token.
147
147
* @param {string } refreshUrl The refresh endpoint URL.
148
- * @return {Service_ } This service, for chaining.
148
+ * @return {! Service_ } This service, for chaining.
149
149
*/
150
150
Service_ . prototype . setRefreshUrl = function ( refreshUrl ) {
151
151
this . refreshUrl_ = refreshUrl ;
@@ -155,7 +155,7 @@ Service_.prototype.setRefreshUrl = function(refreshUrl) {
155
155
/**
156
156
* Sets the format of the returned token. Default: OAuth2.TOKEN_FORMAT.JSON.
157
157
* @param {OAuth2.TOKEN_FORMAT } tokenFormat The format of the returned token.
158
- * @return {Service_ } This service, for chaining.
158
+ * @return {! Service_ } This service, for chaining.
159
159
*/
160
160
Service_ . prototype . setTokenFormat = function ( tokenFormat ) {
161
161
this . tokenFormat_ = tokenFormat ;
@@ -166,7 +166,7 @@ Service_.prototype.setTokenFormat = function(tokenFormat) {
166
166
* Sets the additional HTTP headers that should be sent when retrieving or
167
167
* refreshing the access token.
168
168
* @param {Object.<string,string> } tokenHeaders A map of header names to values.
169
- * @return {Service_ } This service, for chaining.
169
+ * @return {! Service_ } This service, for chaining.
170
170
*/
171
171
Service_ . prototype . setTokenHeaders = function ( tokenHeaders ) {
172
172
this . tokenHeaders_ = tokenHeaders ;
@@ -190,7 +190,7 @@ Service_.prototype.setTokenHeaders = function(tokenHeaders) {
190
190
* request.
191
191
* @param {tokenHandler } tokenHandler tokenHandler A function to invoke on the
192
192
* payload of the request for an access token.
193
- * @return {Service_ } This service, for chaining.
193
+ * @return {! Service_ } This service, for chaining.
194
194
*/
195
195
Service_ . prototype . setTokenPayloadHandler = function ( tokenHandler ) {
196
196
this . tokenPayloadHandler_ = tokenHandler ;
@@ -204,7 +204,7 @@ Service_.prototype.setTokenPayloadHandler = function(tokenHandler) {
204
204
* which should be passed to this service's <code>handleCallback()</code> method
205
205
* to complete the process.
206
206
* @param {string } callbackFunctionName The name of the callback function.
207
- * @return {Service_ } This service, for chaining.
207
+ * @return {! Service_ } This service, for chaining.
208
208
*/
209
209
Service_ . prototype . setCallbackFunction = function ( callbackFunctionName ) {
210
210
this . callbackFunctionName_ = callbackFunctionName ;
@@ -221,7 +221,7 @@ Service_.prototype.setCallbackFunction = function(callbackFunctionName) {
221
221
* the Script Editor, and then click on the link "Google Developers Console" in
222
222
* the resulting dialog.
223
223
* @param {string } clientId The client ID to use for the OAuth flow.
224
- * @return {Service_ } This service, for chaining.
224
+ * @return {! Service_ } This service, for chaining.
225
225
*/
226
226
Service_ . prototype . setClientId = function ( clientId ) {
227
227
this . clientId_ = clientId ;
@@ -233,7 +233,7 @@ Service_.prototype.setClientId = function(clientId) {
233
233
* documentation for <code>setClientId()</code> for more information on how to
234
234
* create client IDs and secrets.
235
235
* @param {string } clientSecret The client secret to use for the OAuth flow.
236
- * @return {Service_ } This service, for chaining.
236
+ * @return {! Service_ } This service, for chaining.
237
237
*/
238
238
Service_ . prototype . setClientSecret = function ( clientSecret ) {
239
239
this . clientSecret_ = clientSecret ;
@@ -246,7 +246,7 @@ Service_.prototype.setClientSecret = function(clientSecret) {
246
246
* may be appropriate if you want to share access across users.
247
247
* @param {PropertiesService.Properties } propertyStore The property store to use
248
248
* when persisting credentials.
249
- * @return {Service_ } This service, for chaining.
249
+ * @return {! Service_ } This service, for chaining.
250
250
* @see https://developers.google.com/apps-script/reference/properties/
251
251
*/
252
252
Service_ . prototype . setPropertyStore = function ( propertyStore ) {
@@ -261,7 +261,7 @@ Service_.prototype.setPropertyStore = function(propertyStore) {
261
261
* may be appropriate if you want to share access across users.
262
262
* @param {CacheService.Cache } cache The cache to use when persisting
263
263
* credentials.
264
- * @return {Service_ } This service, for chaining.
264
+ * @return {! Service_ } This service, for chaining.
265
265
* @see https://developers.google.com/apps-script/reference/cache/
266
266
*/
267
267
Service_ . prototype . setCache = function ( cache ) {
@@ -275,7 +275,7 @@ Service_.prototype.setCache = function(cache) {
275
275
* stored credentials at a time. This can prevent race conditions that arise
276
276
* when two executions attempt to refresh an expired token.
277
277
* @param {LockService.Lock } lock The lock to use when accessing credentials.
278
- * @return {Service_ } This service, for chaining.
278
+ * @return {! Service_ } This service, for chaining.
279
279
* @see https://developers.google.com/apps-script/reference/lock/
280
280
*/
281
281
Service_ . prototype . setLock = function ( lock ) {
@@ -290,7 +290,7 @@ Service_.prototype.setLock = function(lock) {
290
290
* @param {string|Array.<string> } scope The scope or scopes to request.
291
291
* @param {string } [optSeparator] The optional separator to use when joining
292
292
* multiple scopes. Default: space.
293
- * @return {Service_ } This service, for chaining.
293
+ * @return {! Service_ } This service, for chaining.
294
294
*/
295
295
Service_ . prototype . setScope = function ( scope , optSeparator ) {
296
296
var separator = optSeparator || ' ' ;
@@ -304,7 +304,7 @@ Service_.prototype.setScope = function(scope, optSeparator) {
304
304
* on what parameter values they support.
305
305
* @param {string } name The parameter name.
306
306
* @param {string } value The parameter value.
307
- * @return {Service_ } This service, for chaining.
307
+ * @return {! Service_ } This service, for chaining.
308
308
*/
309
309
Service_ . prototype . setParam = function ( name , value ) {
310
310
this . params_ [ name ] = value ;
@@ -314,7 +314,7 @@ Service_.prototype.setParam = function(name, value) {
314
314
/**
315
315
* Sets the private key to use for Service Account authorization.
316
316
* @param {string } privateKey The private key.
317
- * @return {Service_ } This service, for chaining.
317
+ * @return {! Service_ } This service, for chaining.
318
318
*/
319
319
Service_ . prototype . setPrivateKey = function ( privateKey ) {
320
320
this . privateKey_ = privateKey ;
@@ -325,7 +325,7 @@ Service_.prototype.setPrivateKey = function(privateKey) {
325
325
* Sets the issuer (iss) value to use for Service Account authorization.
326
326
* If not set the client ID will be used instead.
327
327
* @param {string } issuer This issuer value
328
- * @return {Service_ } This service, for chaining.
328
+ * @return {! Service_ } This service, for chaining.
329
329
*/
330
330
Service_ . prototype . setIssuer = function ( issuer ) {
331
331
this . issuer_ = issuer ;
@@ -336,7 +336,7 @@ Service_.prototype.setIssuer = function(issuer) {
336
336
* Sets additional JWT claims to use for Service Account authorization.
337
337
* @param {Object.<string,string> } additionalClaims The additional claims, as
338
338
* key-value pairs.
339
- * @return {Service_ } This service, for chaining.
339
+ * @return {! Service_ } This service, for chaining.
340
340
*/
341
341
Service_ . prototype . setAdditionalClaims = function ( additionalClaims ) {
342
342
this . additionalClaims_ = additionalClaims ;
@@ -346,7 +346,7 @@ Service_.prototype.setAdditionalClaims = function(additionalClaims) {
346
346
/**
347
347
* Sets the subject (sub) value to use for Service Account authorization.
348
348
* @param {string } subject This subject value
349
- * @return {Service_ } This service, for chaining.
349
+ * @return {! Service_ } This service, for chaining.
350
350
*/
351
351
Service_ . prototype . setSubject = function ( subject ) {
352
352
this . subject_ = subject ;
@@ -357,7 +357,7 @@ Service_.prototype.setSubject = function(subject) {
357
357
* Sets number of minutes that a token obtained through Service Account
358
358
* authorization should be valid. Default: 60 minutes.
359
359
* @param {string } expirationMinutes The expiration duration in minutes.
360
- * @return {Service_ } This service, for chaining.
360
+ * @return {! Service_ } This service, for chaining.
361
361
*/
362
362
Service_ . prototype . setExpirationMinutes = function ( expirationMinutes ) {
363
363
this . expirationMinutes_ = expirationMinutes ;
@@ -371,7 +371,7 @@ Service_.prototype.setExpirationMinutes = function(expirationMinutes) {
371
371
* it to "client_credentials" and then also set the token headers to include
372
372
* the Authorization header required by the OAuth2 provider.
373
373
* @param {string } grantType The OAuth2 grant_type value.
374
- * @return {Service_ } This service, for chaining.
374
+ * @return {! Service_ } This service, for chaining.
375
375
*/
376
376
Service_ . prototype . setGrantType = function ( grantType ) {
377
377
this . grantType_ = grantType ;
@@ -383,7 +383,7 @@ Service_.prototype.setGrantType = function(grantType) {
383
383
* library will provide this value automatically, but in some rare cases you may
384
384
* need to override it.
385
385
* @param {string } redirectUri The redirect URI.
386
- * @return {Service_ } This service, for chaining.
386
+ * @return {! Service_ } This service, for chaining.
387
387
*/
388
388
Service_ . prototype . setRedirectUri = function ( redirectUri ) {
389
389
this . redirectUri_ = redirectUri ;
@@ -540,10 +540,11 @@ Service_.prototype.getIdToken = function() {
540
540
541
541
/**
542
542
* Resets the service, removing access and requiring the service to be
543
- * re-authorized.
543
+ * re-authorized. Also removes any additional values stored in the service's
544
+ * storage.
544
545
*/
545
546
Service_ . prototype . reset = function ( ) {
546
- this . getStorage ( ) . removeValue ( null ) ;
547
+ this . getStorage ( ) . reset ( ) ;
547
548
} ;
548
549
549
550
/**
@@ -585,7 +586,7 @@ Service_.prototype.fetchToken_ = function(payload, optUrl) {
585
586
/**
586
587
* Gets the token from a UrlFetchApp response.
587
588
* @param {UrlFetchApp.HTTPResponse } response The response object.
588
- * @return {Object } The parsed token.
589
+ * @return {! Object } The parsed token.
589
590
* @throws If the token cannot be parsed or the response contained an error.
590
591
* @private
591
592
*/
@@ -612,7 +613,7 @@ Service_.prototype.getTokenFromResponse_ = function(response) {
612
613
/**
613
614
* Parses the token using the service's token format.
614
615
* @param {string } content The serialized token content.
615
- * @return {Object } The parsed token.
616
+ * @return {! Object } The parsed token.
616
617
* @private
617
618
*/
618
619
Service_ . prototype . parseToken_ = function ( content ) {
@@ -913,7 +914,7 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
913
914
914
915
if ( ! optSkipMemoryCheck ) {
915
916
// Check in-memory cache.
916
- if ( value = this . memory_ [ key ] ) {
917
+ if ( value = this . memory_ [ prefixedKey ] ) {
917
918
if ( value === Storage_ . CACHE_NULL_VALUE ) {
918
919
return null ;
919
920
}
@@ -924,7 +925,7 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
924
925
// Check cache.
925
926
if ( this . cache_ && ( jsonValue = this . cache_ . get ( prefixedKey ) ) ) {
926
927
value = JSON . parse ( jsonValue ) ;
927
- this . memory_ [ key ] = value ;
928
+ this . memory_ [ prefixedKey ] = value ;
928
929
if ( value === Storage_ . CACHE_NULL_VALUE ) {
929
930
return null ;
930
931
}
@@ -939,13 +940,13 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
939
940
jsonValue , Storage_ . CACHE_EXPIRATION_TIME_SECONDS ) ;
940
941
}
941
942
value = JSON . parse ( jsonValue ) ;
942
- this . memory_ [ key ] = value ;
943
+ this . memory_ [ prefixedKey ] = value ;
943
944
return value ;
944
945
}
945
946
946
947
// Not found. Store a special null value in the memory and cache to reduce
947
948
// hits on the PropertiesService.
948
- this . memory_ [ key ] = Storage_ . CACHE_NULL_VALUE ;
949
+ this . memory_ [ prefixedKey ] = Storage_ . CACHE_NULL_VALUE ;
949
950
if ( this . cache_ ) {
950
951
this . cache_ . put ( prefixedKey , JSON . stringify ( Storage_ . CACHE_NULL_VALUE ) ,
951
952
Storage_ . CACHE_EXPIRATION_TIME_SECONDS ) ;
@@ -968,7 +969,7 @@ Storage_.prototype.setValue = function(key, value) {
968
969
this . cache_ . put ( prefixedKey , jsonValue ,
969
970
Storage_ . CACHE_EXPIRATION_TIME_SECONDS ) ;
970
971
}
971
- this . memory_ [ key ] = value ;
972
+ this . memory_ [ prefixedKey ] = value ;
972
973
} ;
973
974
974
975
/**
@@ -977,13 +978,39 @@ Storage_.prototype.setValue = function(key, value) {
977
978
*/
978
979
Storage_ . prototype . removeValue = function ( key ) {
979
980
var prefixedKey = this . getPrefixedKey_ ( key ) ;
981
+ this . removeValueWithPrefixedKey_ ( prefixedKey ) ;
982
+ } ;
983
+
984
+ /**
985
+ * Resets the storage, removing all stored data.
986
+ * @param {string } key The key.
987
+ */
988
+ Storage_ . prototype . reset = function ( ) {
989
+ var prefix = this . getPrefixedKey_ ( ) ;
990
+ var prefixedKeys = Object . keys ( this . memory_ ) ;
991
+ if ( this . properties_ ) {
992
+ var props = this . properties_ . getProperties ( ) ;
993
+ prefixedKeys = Object . keys ( props ) . filter ( function ( prefixedKey ) {
994
+ return prefixedKey === prefix || prefixedKey . indexOf ( prefix + '.' ) === 0 ;
995
+ } ) ;
996
+ }
997
+ for ( var i = 0 ; i < prefixedKeys . length ; i ++ ) {
998
+ this . removeValueWithPrefixedKey_ ( prefixedKeys [ i ] ) ;
999
+ } ;
1000
+ } ;
1001
+
1002
+ /**
1003
+ * Removes a stored value.
1004
+ * @param {string } key The key.
1005
+ */
1006
+ Storage_ . prototype . removeValueWithPrefixedKey_ = function ( prefixedKey ) {
980
1007
if ( this . properties_ ) {
981
1008
this . properties_ . deleteProperty ( prefixedKey ) ;
982
1009
}
983
1010
if ( this . cache_ ) {
984
1011
this . cache_ . remove ( prefixedKey ) ;
985
1012
}
986
- delete this . memory_ [ key ] ;
1013
+ delete this . memory_ [ prefixedKey ] ;
987
1014
} ;
988
1015
989
1016
/**
@@ -1053,7 +1080,7 @@ function validate_(params) {
1053
1080
/**
1054
1081
* Gets the time in seconds, rounded down to the nearest second.
1055
1082
* @param {Date } date The Date object to convert.
1056
- * @return {Number } The number of seconds since the epoch.
1083
+ * @return {number } The number of seconds since the epoch.
1057
1084
* @private
1058
1085
*/
1059
1086
function getTimeInSeconds_ ( date ) {
0 commit comments