blob: 6c463ad05498e66599092a7b3b970010e4975cc8 (
plain)
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
|
export type AuthToken = {
username: string;
access_token: string;
token_type: string;
expires: number;
}
export class User {
constructor (private _bearerToken: AuthToken) {
}
public get user(): string | null {
return this._bearerToken && this._bearerToken.username;
};
public get token(): string | null {
return this._bearerToken && this._bearerToken.access_token;
}
public get tokenType(): string | null {
return this._bearerToken && this._bearerToken.token_type;
}
public get isValid(): boolean {
return (this._bearerToken && (new Date().valueOf()) < this._bearerToken.expires) || false;
}
public toString() {
return JSON.stringify(this._bearerToken);
}
public static fromString(data: string) {
return new User(JSON.parse(data));
}
}
|