-
Notifications
You must be signed in to change notification settings - Fork 53
/
tns-oauth-token-cache.ts
41 lines (29 loc) · 1.22 KB
/
tns-oauth-token-cache.ts
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
/// <reference path="references.d.ts" />
import * as TnsOAuth from './tns-oauth-interfaces';
import * as applicationSettingsModule from "application-settings";
const TNS_OAUTH_KEY = "TNS_OAUTH_KEY";
export class TnsOAuthTokenCache {
public static hasToken(): boolean {
return applicationSettingsModule.hasKey(TNS_OAUTH_KEY);
}
public static getToken(): TnsOAuth.ITnsOAuthTokenResult {
if (applicationSettingsModule.hasKey(TNS_OAUTH_KEY)) {
let trStr = applicationSettingsModule.getString(TNS_OAUTH_KEY);
let tr = <TnsOAuth.ITnsOAuthTokenResult>JSON.parse(trStr);
if (tr.accessTokenExpiration) {
tr.accessTokenExpiration = new Date(tr.accessTokenExpiration.toString());
}
if (tr.refreshTokenExpiration) {
tr.refreshTokenExpiration = new Date(tr.refreshTokenExpiration.toString());
}
return tr;
}
else return null;
}
public static setToken(token: TnsOAuth.ITnsOAuthTokenResult) {
applicationSettingsModule.setString(TNS_OAUTH_KEY, JSON.stringify(token));
}
public static removeToken() {
applicationSettingsModule.remove(TNS_OAUTH_KEY);
}
}