Skip to content

Commit 7c7b090

Browse files
author
Eric Koleda
committed
1.38.0
1 parent 15aefb9 commit 7c7b090

File tree

8 files changed

+542
-104
lines changed

8 files changed

+542
-104
lines changed

dist/OAuth2.gs

+59-32
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Service_.LOCK_EXPIRATION_MILLISECONDS_ = 30 * 1000;
123123
* this URL should be
124124
* https://accounts.google.com/o/oauth2/auth.
125125
* @param {string} authorizationBaseUrl The authorization endpoint base URL.
126-
* @return {Service_} This service, for chaining.
126+
* @return {!Service_} This service, for chaining.
127127
*/
128128
Service_.prototype.setAuthorizationBaseUrl = function(authorizationBaseUrl) {
129129
this.authorizationBaseUrl_ = authorizationBaseUrl;
@@ -134,7 +134,7 @@ Service_.prototype.setAuthorizationBaseUrl = function(authorizationBaseUrl) {
134134
* Sets the service's token URL (required). For Google services this URL should
135135
* be https://accounts.google.com/o/oauth2/token.
136136
* @param {string} tokenUrl The token endpoint URL.
137-
* @return {Service_} This service, for chaining.
137+
* @return {!Service_} This service, for chaining.
138138
*/
139139
Service_.prototype.setTokenUrl = function(tokenUrl) {
140140
this.tokenUrl_ = tokenUrl;
@@ -145,7 +145,7 @@ Service_.prototype.setTokenUrl = function(tokenUrl) {
145145
* Sets the service's refresh URL. Some OAuth providers require a different URL
146146
* to be used when generating access tokens from a refresh token.
147147
* @param {string} refreshUrl The refresh endpoint URL.
148-
* @return {Service_} This service, for chaining.
148+
* @return {!Service_} This service, for chaining.
149149
*/
150150
Service_.prototype.setRefreshUrl = function(refreshUrl) {
151151
this.refreshUrl_ = refreshUrl;
@@ -155,7 +155,7 @@ Service_.prototype.setRefreshUrl = function(refreshUrl) {
155155
/**
156156
* Sets the format of the returned token. Default: OAuth2.TOKEN_FORMAT.JSON.
157157
* @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.
159159
*/
160160
Service_.prototype.setTokenFormat = function(tokenFormat) {
161161
this.tokenFormat_ = tokenFormat;
@@ -166,7 +166,7 @@ Service_.prototype.setTokenFormat = function(tokenFormat) {
166166
* Sets the additional HTTP headers that should be sent when retrieving or
167167
* refreshing the access token.
168168
* @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.
170170
*/
171171
Service_.prototype.setTokenHeaders = function(tokenHeaders) {
172172
this.tokenHeaders_ = tokenHeaders;
@@ -190,7 +190,7 @@ Service_.prototype.setTokenHeaders = function(tokenHeaders) {
190190
* request.
191191
* @param {tokenHandler} tokenHandler tokenHandler A function to invoke on the
192192
* payload of the request for an access token.
193-
* @return {Service_} This service, for chaining.
193+
* @return {!Service_} This service, for chaining.
194194
*/
195195
Service_.prototype.setTokenPayloadHandler = function(tokenHandler) {
196196
this.tokenPayloadHandler_ = tokenHandler;
@@ -204,7 +204,7 @@ Service_.prototype.setTokenPayloadHandler = function(tokenHandler) {
204204
* which should be passed to this service's <code>handleCallback()</code> method
205205
* to complete the process.
206206
* @param {string} callbackFunctionName The name of the callback function.
207-
* @return {Service_} This service, for chaining.
207+
* @return {!Service_} This service, for chaining.
208208
*/
209209
Service_.prototype.setCallbackFunction = function(callbackFunctionName) {
210210
this.callbackFunctionName_ = callbackFunctionName;
@@ -221,7 +221,7 @@ Service_.prototype.setCallbackFunction = function(callbackFunctionName) {
221221
* the Script Editor, and then click on the link "Google Developers Console" in
222222
* the resulting dialog.
223223
* @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.
225225
*/
226226
Service_.prototype.setClientId = function(clientId) {
227227
this.clientId_ = clientId;
@@ -233,7 +233,7 @@ Service_.prototype.setClientId = function(clientId) {
233233
* documentation for <code>setClientId()</code> for more information on how to
234234
* create client IDs and secrets.
235235
* @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.
237237
*/
238238
Service_.prototype.setClientSecret = function(clientSecret) {
239239
this.clientSecret_ = clientSecret;
@@ -246,7 +246,7 @@ Service_.prototype.setClientSecret = function(clientSecret) {
246246
* may be appropriate if you want to share access across users.
247247
* @param {PropertiesService.Properties} propertyStore The property store to use
248248
* when persisting credentials.
249-
* @return {Service_} This service, for chaining.
249+
* @return {!Service_} This service, for chaining.
250250
* @see https://developers.google.com/apps-script/reference/properties/
251251
*/
252252
Service_.prototype.setPropertyStore = function(propertyStore) {
@@ -261,7 +261,7 @@ Service_.prototype.setPropertyStore = function(propertyStore) {
261261
* may be appropriate if you want to share access across users.
262262
* @param {CacheService.Cache} cache The cache to use when persisting
263263
* credentials.
264-
* @return {Service_} This service, for chaining.
264+
* @return {!Service_} This service, for chaining.
265265
* @see https://developers.google.com/apps-script/reference/cache/
266266
*/
267267
Service_.prototype.setCache = function(cache) {
@@ -275,7 +275,7 @@ Service_.prototype.setCache = function(cache) {
275275
* stored credentials at a time. This can prevent race conditions that arise
276276
* when two executions attempt to refresh an expired token.
277277
* @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.
279279
* @see https://developers.google.com/apps-script/reference/lock/
280280
*/
281281
Service_.prototype.setLock = function(lock) {
@@ -290,7 +290,7 @@ Service_.prototype.setLock = function(lock) {
290290
* @param {string|Array.<string>} scope The scope or scopes to request.
291291
* @param {string} [optSeparator] The optional separator to use when joining
292292
* multiple scopes. Default: space.
293-
* @return {Service_} This service, for chaining.
293+
* @return {!Service_} This service, for chaining.
294294
*/
295295
Service_.prototype.setScope = function(scope, optSeparator) {
296296
var separator = optSeparator || ' ';
@@ -304,7 +304,7 @@ Service_.prototype.setScope = function(scope, optSeparator) {
304304
* on what parameter values they support.
305305
* @param {string} name The parameter name.
306306
* @param {string} value The parameter value.
307-
* @return {Service_} This service, for chaining.
307+
* @return {!Service_} This service, for chaining.
308308
*/
309309
Service_.prototype.setParam = function(name, value) {
310310
this.params_[name] = value;
@@ -314,7 +314,7 @@ Service_.prototype.setParam = function(name, value) {
314314
/**
315315
* Sets the private key to use for Service Account authorization.
316316
* @param {string} privateKey The private key.
317-
* @return {Service_} This service, for chaining.
317+
* @return {!Service_} This service, for chaining.
318318
*/
319319
Service_.prototype.setPrivateKey = function(privateKey) {
320320
this.privateKey_ = privateKey;
@@ -325,7 +325,7 @@ Service_.prototype.setPrivateKey = function(privateKey) {
325325
* Sets the issuer (iss) value to use for Service Account authorization.
326326
* If not set the client ID will be used instead.
327327
* @param {string} issuer This issuer value
328-
* @return {Service_} This service, for chaining.
328+
* @return {!Service_} This service, for chaining.
329329
*/
330330
Service_.prototype.setIssuer = function(issuer) {
331331
this.issuer_ = issuer;
@@ -336,7 +336,7 @@ Service_.prototype.setIssuer = function(issuer) {
336336
* Sets additional JWT claims to use for Service Account authorization.
337337
* @param {Object.<string,string>} additionalClaims The additional claims, as
338338
* key-value pairs.
339-
* @return {Service_} This service, for chaining.
339+
* @return {!Service_} This service, for chaining.
340340
*/
341341
Service_.prototype.setAdditionalClaims = function(additionalClaims) {
342342
this.additionalClaims_ = additionalClaims;
@@ -346,7 +346,7 @@ Service_.prototype.setAdditionalClaims = function(additionalClaims) {
346346
/**
347347
* Sets the subject (sub) value to use for Service Account authorization.
348348
* @param {string} subject This subject value
349-
* @return {Service_} This service, for chaining.
349+
* @return {!Service_} This service, for chaining.
350350
*/
351351
Service_.prototype.setSubject = function(subject) {
352352
this.subject_ = subject;
@@ -357,7 +357,7 @@ Service_.prototype.setSubject = function(subject) {
357357
* Sets number of minutes that a token obtained through Service Account
358358
* authorization should be valid. Default: 60 minutes.
359359
* @param {string} expirationMinutes The expiration duration in minutes.
360-
* @return {Service_} This service, for chaining.
360+
* @return {!Service_} This service, for chaining.
361361
*/
362362
Service_.prototype.setExpirationMinutes = function(expirationMinutes) {
363363
this.expirationMinutes_ = expirationMinutes;
@@ -371,7 +371,7 @@ Service_.prototype.setExpirationMinutes = function(expirationMinutes) {
371371
* it to "client_credentials" and then also set the token headers to include
372372
* the Authorization header required by the OAuth2 provider.
373373
* @param {string} grantType The OAuth2 grant_type value.
374-
* @return {Service_} This service, for chaining.
374+
* @return {!Service_} This service, for chaining.
375375
*/
376376
Service_.prototype.setGrantType = function(grantType) {
377377
this.grantType_ = grantType;
@@ -383,7 +383,7 @@ Service_.prototype.setGrantType = function(grantType) {
383383
* library will provide this value automatically, but in some rare cases you may
384384
* need to override it.
385385
* @param {string} redirectUri The redirect URI.
386-
* @return {Service_} This service, for chaining.
386+
* @return {!Service_} This service, for chaining.
387387
*/
388388
Service_.prototype.setRedirectUri = function(redirectUri) {
389389
this.redirectUri_ = redirectUri;
@@ -540,10 +540,11 @@ Service_.prototype.getIdToken = function() {
540540

541541
/**
542542
* 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.
544545
*/
545546
Service_.prototype.reset = function() {
546-
this.getStorage().removeValue(null);
547+
this.getStorage().reset();
547548
};
548549

549550
/**
@@ -585,7 +586,7 @@ Service_.prototype.fetchToken_ = function(payload, optUrl) {
585586
/**
586587
* Gets the token from a UrlFetchApp response.
587588
* @param {UrlFetchApp.HTTPResponse} response The response object.
588-
* @return {Object} The parsed token.
589+
* @return {!Object} The parsed token.
589590
* @throws If the token cannot be parsed or the response contained an error.
590591
* @private
591592
*/
@@ -612,7 +613,7 @@ Service_.prototype.getTokenFromResponse_ = function(response) {
612613
/**
613614
* Parses the token using the service's token format.
614615
* @param {string} content The serialized token content.
615-
* @return {Object} The parsed token.
616+
* @return {!Object} The parsed token.
616617
* @private
617618
*/
618619
Service_.prototype.parseToken_ = function(content) {
@@ -913,7 +914,7 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
913914

914915
if (!optSkipMemoryCheck) {
915916
// Check in-memory cache.
916-
if (value = this.memory_[key]) {
917+
if (value = this.memory_[prefixedKey]) {
917918
if (value === Storage_.CACHE_NULL_VALUE) {
918919
return null;
919920
}
@@ -924,7 +925,7 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
924925
// Check cache.
925926
if (this.cache_ && (jsonValue = this.cache_.get(prefixedKey))) {
926927
value = JSON.parse(jsonValue);
927-
this.memory_[key] = value;
928+
this.memory_[prefixedKey] = value;
928929
if (value === Storage_.CACHE_NULL_VALUE) {
929930
return null;
930931
}
@@ -939,13 +940,13 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
939940
jsonValue, Storage_.CACHE_EXPIRATION_TIME_SECONDS);
940941
}
941942
value = JSON.parse(jsonValue);
942-
this.memory_[key] = value;
943+
this.memory_[prefixedKey] = value;
943944
return value;
944945
}
945946

946947
// Not found. Store a special null value in the memory and cache to reduce
947948
// hits on the PropertiesService.
948-
this.memory_[key] = Storage_.CACHE_NULL_VALUE;
949+
this.memory_[prefixedKey] = Storage_.CACHE_NULL_VALUE;
949950
if (this.cache_) {
950951
this.cache_.put(prefixedKey, JSON.stringify(Storage_.CACHE_NULL_VALUE),
951952
Storage_.CACHE_EXPIRATION_TIME_SECONDS);
@@ -968,7 +969,7 @@ Storage_.prototype.setValue = function(key, value) {
968969
this.cache_.put(prefixedKey, jsonValue,
969970
Storage_.CACHE_EXPIRATION_TIME_SECONDS);
970971
}
971-
this.memory_[key] = value;
972+
this.memory_[prefixedKey] = value;
972973
};
973974

974975
/**
@@ -977,13 +978,39 @@ Storage_.prototype.setValue = function(key, value) {
977978
*/
978979
Storage_.prototype.removeValue = function(key) {
979980
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) {
9801007
if (this.properties_) {
9811008
this.properties_.deleteProperty(prefixedKey);
9821009
}
9831010
if (this.cache_) {
9841011
this.cache_.remove(prefixedKey);
9851012
}
986-
delete this.memory_[key];
1013+
delete this.memory_[prefixedKey];
9871014
};
9881015

9891016
/**
@@ -1053,7 +1080,7 @@ function validate_(params) {
10531080
/**
10541081
* Gets the time in seconds, rounded down to the nearest second.
10551082
* @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.
10571084
* @private
10581085
*/
10591086
function getTimeInSeconds_(date) {

0 commit comments

Comments
 (0)