forked from OneIdentity/safeguard.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalStorage.js
72 lines (64 loc) · 1.57 KB
/
LocalStorage.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* (Public) Default storage class for NodeJS implementations of SafeguardJS. This
* uses memory for storing and retrieving the authentication information for
* communicating with the safeguard appliance.
*
* If implementing a different storage class other than LocalStorage (such as a
* database), the new class must be written with all of the same methods as those
* defined here.
*/
class LocalStorage {
constructor() {
this.hostName = '';
this.accessToken = '';
this.userToken = '';
}
/**
* Gets the access token from storage.
* @returns {string} The access token.
*/
getAccessToken() {
return this.accessToken;
}
/**
* Gets the user token from storage.
* @returns {string} The user token.
*/
getUserToken(){
return this.userToken;
}
/**
* Gets the host name from storage.
* @returns {string} The host name.
*/
getHostName(){
return this.hostName;
}
/**
* Writes the access token to storage.
*/
setAccessToken(accessToken) {
this.accessToken = accessToken;
}
/**
* Writes the user token to storage.
*/
setUserToken(userToken) {
this.userToken = userToken;
}
/**
* Writes the host name to storage.
*/
setHostName(hostName) {
this.hostName = hostName;
}
/**
* Clears all values from storage.
*/
clearStorage() {
this.setUserToken('');
this.setAccessToken('');
this.setHostName('');
}
}
module.exports = { LocalStorage }