mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
parse function
This commit is contained in:
parent
7b89ad6bf7
commit
240e5ba5ab
@ -1,6 +1,7 @@
|
|||||||
export class U2f {
|
export class U2f {
|
||||||
private iframe: HTMLIFrameElement = null;
|
private iframe: HTMLIFrameElement = null;
|
||||||
private connectorLink: HTMLAnchorElement;
|
private connectorLink: HTMLAnchorElement;
|
||||||
|
private parseFunction = this.parseMessage.bind(this);
|
||||||
|
|
||||||
constructor(private win: Window, private webVaultUrl: string, private successCallback: Function,
|
constructor(private win: Window, private webVaultUrl: string, private successCallback: Function,
|
||||||
private errorCallback: Function, private infoCallback: Function) {
|
private errorCallback: Function, private infoCallback: Function) {
|
||||||
@ -17,7 +18,7 @@ export class U2f {
|
|||||||
this.iframe = this.win.document.getElementById('u2f_iframe') as HTMLIFrameElement;
|
this.iframe = this.win.document.getElementById('u2f_iframe') as HTMLIFrameElement;
|
||||||
this.iframe.src = this.connectorLink.href;
|
this.iframe.src = this.connectorLink.href;
|
||||||
|
|
||||||
this.win.addEventListener('message', (e) => this.parseMessage(e), false);
|
this.win.addEventListener('message', this.parseFunction, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
@ -43,14 +44,11 @@ export class U2f {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.win.removeEventListener('message', (e) => this.parseMessage(e), false);
|
this.win.removeEventListener('message', this.parseFunction, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseMessage(event: any) {
|
private parseMessage(event: MessageEvent) {
|
||||||
console.log('got u2f event');
|
|
||||||
console.log(event);
|
|
||||||
if (!this.validMessage(event)) {
|
if (!this.validMessage(event)) {
|
||||||
this.errorCallback('Invalid message.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +62,7 @@ export class U2f {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private validMessage(event: any) {
|
private validMessage(event: MessageEvent) {
|
||||||
if (event.origin == null || event.origin === '' || event.origin !== (this.connectorLink as any).origin ||
|
if (event.origin == null || event.origin === '' || event.origin !== (this.connectorLink as any).origin ||
|
||||||
event.data == null || typeof (event.data) !== 'string') {
|
event.data == null || typeof (event.data) !== 'string') {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user