-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken-store.js
54 lines (45 loc) · 1.06 KB
/
token-store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @fileoverview In-Memory Token Store
* @author mwiller
* @module box-node-sdk/token-store
*/
'use strict';
var store = new Map();
/**
* Basic in-memory Token Store, not suitable for use in production!
* @param {string} userID The ID of the user whose tokens will be stored
* @constructor
*/
function TokenStore(userID) {
this.userID = userID;
}
TokenStore.prototype = {
/**
* Read the user's tokens from the store
* @param {Function} callback Passed the user's tokens
* @returns {void}
*/
read: function(callback) {
callback(null, store.get(this.userID));
},
/**
* Write the user's tokens to the store
* @param {Object} tokenInfo The user's token info
* @param {Function} callback The callback
* @returns {void}
*/
write: function(tokenInfo, callback) {
store.set(this.userID, tokenInfo);
callback();
},
/**
* Clears the user's tokens from the store
* @param {Function} callback The callback
* @returns {void}
*/
clear: function(callback) {
store.delete(this.userID);
callback();
}
};
module.exports = TokenStore;