Skip to content

Commit 6b5950e

Browse files
author
Eric Koleda
committed
Release version 24
1 parent c8c63ec commit 6b5950e

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

dist/OAuth2.gs

+28-14
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,12 @@ Service_.prototype.reset = function() {
454454
validate_({
455455
'Property store': this.propertyStore_
456456
});
457-
var key = this.getPropertyKey_(this.serviceName_);
457+
var key = this.getPropertyKey_();
458458
this.propertyStore_.deleteProperty(key);
459459
if (this.cache_) {
460460
this.cache_.remove(key);
461461
}
462+
this.token_ = null;
462463
};
463464

464465
/**
@@ -585,12 +586,13 @@ Service_.prototype.saveToken_ = function(token) {
585586
validate_({
586587
'Property store': this.propertyStore_
587588
});
588-
var key = this.getPropertyKey_(this.serviceName_);
589+
var key = this.getPropertyKey_();
589590
var value = JSON.stringify(token);
590591
this.propertyStore_.setProperty(key, value);
591592
if (this.cache_) {
592593
this.cache_.put(key, value, 21600);
593594
}
595+
this.token_ = token;
594596
};
595597

596598
/**
@@ -601,22 +603,34 @@ Service_.prototype.getToken = function() {
601603
validate_({
602604
'Property store': this.propertyStore_
603605
});
604-
var key = this.getPropertyKey_(this.serviceName_);
605-
var token;
606-
if (this.cache_) {
607-
token = this.cache_.get(key);
606+
607+
// Check in-memory cache.
608+
if (this.token_) {
609+
return this.token_;
608610
}
609-
if (!token) {
610-
token = this.propertyStore_.getProperty(key);
611+
612+
var key = this.getPropertyKey_();
613+
var token;
614+
615+
// Check CacheService cache.
616+
if (this.cache_ && (token = this.cache_.get(key))) {
617+
token = JSON.parse(token);
618+
this.token_ = token;
619+
return token;
611620
}
612-
if (token) {
621+
622+
// Check PropertiesService store.
623+
if ((token = this.propertyStore_.getProperty(key))) {
613624
if (this.cache_) {
614625
this.cache_.put(key, token, 21600);
615626
}
616-
return JSON.parse(token);
617-
} else {
618-
return null;
627+
token = JSON.parse(token);
628+
this.token_ = token;
629+
return token;
619630
}
631+
632+
// Not found.
633+
return null;
620634
};
621635

622636
/**
@@ -625,8 +639,8 @@ Service_.prototype.getToken = function() {
625639
* @return {string} The property key.
626640
* @private
627641
*/
628-
Service_.prototype.getPropertyKey_ = function(serviceName) {
629-
return 'oauth2.' + serviceName;
642+
Service_.prototype.getPropertyKey_ = function() {
643+
return 'oauth2.' + this.serviceName_;
630644
};
631645

632646
/**

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apps-script-oauth2",
3-
"version": "1.23.0",
3+
"version": "1.24.0",
44
"description": "OAuth2 for Apps Script is a library for Google Apps Script that provides the ability to create and authorize OAuth2 tokens as well as refresh them when they expire.",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)