OAuthTokens.js
1.48 KB
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
'use strict';
module.exports = class OAuthTokens {
constructor(other) {
this._data = {
accessToken: {
value: null,
expiresAt: -1
},
refreshToken: {
value: null,
expiresAt: -1
}
};
if (other) {
this._setAccessToken(other.accessToken, other.accessTokenExpiresAt);
this._setRefreshToken(other.refreshToken, other.refreshTokenExpiresAt);
}
}
_setAccessToken(token, expiresAt) {
this._data.accessToken.value = token;
this._data.accessToken.expiresAt = expiresAt || -1;
}
_setRefreshToken(token, expiresAt) {
this._data.refreshToken.value = token;
this._data.refreshToken.expiresAt = expiresAt || -1;
}
/**
* Gets the refresh token
* @returns {String}
*/
get refreshToken() {
return this._data.refreshToken.value;
}
/**
* Gets the access token
* @returns {String}
*/
get accessToken() {
return this._data.accessToken.value;
}
/**
* Gets the access token expiry if known
* @returns {number} the timestamp value of the expiry of the access token, or -1 os not known
*/
get accessTokenExpiresAt() {
return this._data.accessToken.expiresAt;
}
/**
* Gets the refresh token expiry if known
* @returns {number} the timestamp value of the expiry of the refresh token, or -1 os not known
*/
get refreshTokenExpiresAt() {
return this._data.refreshToken.expiresAt;
}
toString() {
return JSON.stringify(this._data, null, 2);
}
};