]>
Commit | Line | Data |
---|---|---|
b1794c53 C |
1 | export class Token { |
2 | access_token: string; | |
3 | refresh_token: string; | |
4 | token_type: string; | |
5 | ||
1553e15d C |
6 | constructor (hash?: any) { |
7 | if (hash) { | |
8 | this.access_token = hash.access_token; | |
9 | this.refresh_token = hash.refresh_token; | |
10 | if (hash.token_type === 'bearer') { | |
11 | this.token_type = 'Bearer'; | |
12 | } else { | |
13 | this.token_type = hash.token_type; | |
14 | } | |
15 | } | |
b1794c53 C |
16 | } |
17 | ||
1553e15d C |
18 | static load(): Token { |
19 | return new Token({ | |
20 | access_token: localStorage.getItem('access_token'), | |
21 | refresh_token: localStorage.getItem('refresh_token'), | |
22 | token_type: localStorage.getItem('token_type') | |
23 | }); | |
24 | } | |
25 | ||
26 | save():void { | |
b1794c53 C |
27 | localStorage.setItem('access_token', this.access_token); |
28 | localStorage.setItem('refresh_token', this.refresh_token); | |
29 | localStorage.setItem('token_type', this.token_type); | |
30 | } | |
31 | } |