PeerTube/client/app/shared/users/token.model.ts

33 lines
808 B
TypeScript
Raw Normal View History

2016-03-22 09:51:54 -05:00
export class Token {
access_token: string;
refresh_token: string;
token_type: string;
2016-05-27 10:25:52 -05:00
static load() {
2016-05-11 13:46:45 -05:00
return new Token({
access_token: localStorage.getItem('access_token'),
refresh_token: localStorage.getItem('refresh_token'),
token_type: localStorage.getItem('token_type')
});
}
2016-05-27 10:25:52 -05:00
constructor(hash?: any) {
if (hash) {
this.access_token = hash.access_token;
this.refresh_token = hash.refresh_token;
2016-05-27 10:25:52 -05:00
if (hash.token_type === 'bearer') {
this.token_type = 'Bearer';
} else {
this.token_type = hash.token_type;
}
}
2016-03-22 09:51:54 -05:00
}
2016-05-27 10:25:52 -05:00
save() {
2016-03-22 09:51:54 -05:00
localStorage.setItem('access_token', this.access_token);
localStorage.setItem('refresh_token', this.refresh_token);
localStorage.setItem('token_type', this.token_type);
}
}