Skip to content

Commit 04db530

Browse files
author
Eric Koleda
committed
1.40.0
1 parent 53a4aa9 commit 04db530

File tree

7 files changed

+196
-11
lines changed

7 files changed

+196
-11
lines changed

dist/OAuth2.gs

+27-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var TOKEN_FORMAT = {
3232
FORM_URL_ENCODED: 'application/x-www-form-urlencoded'
3333
};
3434

35+
var STORAGE_PREFIX_ = 'oauth2.';
36+
3537
/**
3638
* Creates a new OAuth2 service with the name specified. It's usually best to
3739
* create and configure your service once at the start of your script, and then
@@ -57,10 +59,34 @@ function getRedirectUri(optScriptId) {
5759
'/usercallback';
5860
}
5961

62+
/**
63+
* Gets the list of services with tokens stored in the given property store.
64+
* This is useful if you connect to the same API with multiple accounts and
65+
* need to keep track of them. If no stored tokens are found this will return
66+
* an empty array.
67+
* @param {PropertiesService.Properties} propertyStore The properties to check.
68+
* @return {Array.<string>} The service names.
69+
*/
70+
function getServiceNames(propertyStore) {
71+
var props = propertyStore.getProperties();
72+
return Object.keys(props).filter(function(key) {
73+
var parts = key.split('.');
74+
return key.indexOf(STORAGE_PREFIX_) == 0 && parts.length > 1 && parts[1];
75+
}).map(function(key) {
76+
return key.split('.')[1];
77+
}).reduce(function(result, key) {
78+
if (result.indexOf(key) < 0) {
79+
result.push(key);
80+
}
81+
return result;
82+
}, []);
83+
}
84+
6085
if (typeof module === 'object') {
6186
module.exports = {
6287
createService: createService,
6388
getRedirectUri: getRedirectUri,
89+
getServiceNames: getServiceNames,
6490
TOKEN_FORMAT: TOKEN_FORMAT
6591
};
6692
}
@@ -676,7 +702,7 @@ Service_.prototype.refresh = function() {
676702
*/
677703
Service_.prototype.getStorage = function() {
678704
if (!this.storage_) {
679-
var prefix = 'oauth2.' + this.serviceName_;
705+
var prefix = STORAGE_PREFIX_ + this.serviceName_;
680706
this.storage_ = new Storage_(prefix, this.propertyStore_, this.cache_);
681707
}
682708
return this.storage_;

docs/Service_.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5145,13 +5145,13 @@ <h5>Returns:</h5>
51455145
</div>
51465146

51475147
<nav>
5148-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
5148+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#getServiceNames">getServiceNames</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
51495149
</nav>
51505150

51515151
<br class="clear">
51525152

51535153
<footer>
5154-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:02:02 GMT-0500 (Eastern Standard Time)
5154+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:48:15 GMT-0500 (Eastern Standard Time)
51555155
</footer>
51565156

51575157
<script> prettyPrint(); </script>

docs/Storage_.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,13 @@ <h5>Parameters:</h5>
10291029
</div>
10301030

10311031
<nav>
1032-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
1032+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#getServiceNames">getServiceNames</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
10331033
</nav>
10341034

10351035
<br class="clear">
10361036

10371037
<footer>
1038-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:02:02 GMT-0500 (Eastern Standard Time)
1038+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:48:15 GMT-0500 (Eastern Standard Time)
10391039
</footer>
10401040

10411041
<script> prettyPrint(); </script>

docs/global.html

+159-2
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,163 @@ <h5>Returns:</h5>
10931093

10941094

10951095

1096+
<h4 class="name" id="getServiceNames"><span class="type-signature"></span>getServiceNames<span class="signature">(propertyStore)</span><span class="type-signature"> &rarr; {Array.&lt;string>}</span></h4>
1097+
1098+
1099+
1100+
1101+
1102+
1103+
<div class="description">
1104+
Gets the list of services with tokens stored in the given property store.
1105+
This is useful if you connect to the same API with multiple accounts and
1106+
need to keep track of them. If no stored tokens are found this will return
1107+
an empty array.
1108+
</div>
1109+
1110+
1111+
1112+
1113+
1114+
1115+
1116+
1117+
1118+
<h5>Parameters:</h5>
1119+
1120+
1121+
<table class="params">
1122+
<thead>
1123+
<tr>
1124+
1125+
<th>Name</th>
1126+
1127+
1128+
<th>Type</th>
1129+
1130+
1131+
1132+
1133+
1134+
<th class="last">Description</th>
1135+
</tr>
1136+
</thead>
1137+
1138+
<tbody>
1139+
1140+
1141+
<tr>
1142+
1143+
<td class="name"><code>propertyStore</code></td>
1144+
1145+
1146+
<td class="type">
1147+
1148+
1149+
<span class="param-type">PropertiesService.Properties</span>
1150+
1151+
1152+
1153+
</td>
1154+
1155+
1156+
1157+
1158+
1159+
<td class="description last">The properties to check.</td>
1160+
</tr>
1161+
1162+
1163+
</tbody>
1164+
</table>
1165+
1166+
1167+
1168+
1169+
1170+
1171+
<dl class="details">
1172+
1173+
1174+
1175+
1176+
1177+
1178+
1179+
1180+
1181+
1182+
1183+
1184+
1185+
1186+
1187+
1188+
1189+
1190+
1191+
1192+
1193+
1194+
1195+
1196+
1197+
1198+
1199+
1200+
1201+
1202+
1203+
1204+
</dl>
1205+
1206+
1207+
1208+
1209+
1210+
1211+
1212+
1213+
1214+
1215+
1216+
1217+
1218+
1219+
1220+
<h5>Returns:</h5>
1221+
1222+
1223+
<div class="param-desc">
1224+
The service names.
1225+
</div>
1226+
1227+
1228+
1229+
<dl>
1230+
<dt>
1231+
Type
1232+
</dt>
1233+
<dd>
1234+
1235+
<span class="param-type">Array.&lt;string></span>
1236+
1237+
1238+
</dd>
1239+
</dl>
1240+
1241+
1242+
1243+
1244+
1245+
1246+
1247+
1248+
1249+
1250+
1251+
1252+
10961253
<h4 class="name" id="toLowerCaseKeys_"><span class="type-signature"></span>toLowerCaseKeys_<span class="signature">(obj)</span><span class="type-signature"> &rarr; {Object}</span></h4>
10971254

10981255

@@ -1553,13 +1710,13 @@ <h5>Returns:</h5>
15531710
</div>
15541711

15551712
<nav>
1556-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
1713+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#getServiceNames">getServiceNames</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
15571714
</nav>
15581715

15591716
<br class="clear">
15601717

15611718
<footer>
1562-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:02:02 GMT-0500 (Eastern Standard Time)
1719+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:48:15 GMT-0500 (Eastern Standard Time)
15631720
</footer>
15641721

15651722
<script> prettyPrint(); </script>

docs/index.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ <h3>How can I connect to multiple OAuth services?</h3>
428428
// GitHub settings ...
429429
}
430430
</code></pre>
431+
<p>You can list all of the service names you've previously stored tokens for using
432+
<code>OAuth2.getServiceNames(propertyStore)</code>.</p>
431433
<h2>Compatibility</h2>
432434
<p>This library was designed to work with any OAuth2 provider, but because of small
433435
differences in how they implement the standard it may be that some APIs
@@ -813,13 +815,13 @@ <h2>Utilities.js</h2>
813815
</div>
814816

815817
<nav>
816-
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
818+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Service_.html">Service_</a></li><li><a href="Storage_.html">Storage_</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createService">createService</a></li><li><a href="global.html#decodeJwt_">decodeJwt_</a></li><li><a href="global.html#encodeJwt_">encodeJwt_</a></li><li><a href="global.html#extend_">extend_</a></li><li><a href="global.html#getRedirectUri">getRedirectUri</a></li><li><a href="global.html#getServiceNames">getServiceNames</a></li><li><a href="global.html#TOKEN_FORMAT">TOKEN_FORMAT</a></li><li><a href="global.html#toLowerCaseKeys_">toLowerCaseKeys_</a></li></ul>
817819
</nav>
818820

819821
<br class="clear">
820822

821823
<footer>
822-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:02:02 GMT-0500 (Eastern Standard Time)
824+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Mon Dec 14 2020 20:48:15 GMT-0500 (Eastern Standard Time)
823825
</footer>
824826

825827
<script> prettyPrint(); </script>

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.39.0",
3+
"version": "1.40.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)