1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-21 02:11:54 +01:00

copy totp from each implementation of autofill

This commit is contained in:
Kyle Spearrin 2018-04-23 10:02:30 -04:00
parent 271f9df8ae
commit 06e56f0b57
5 changed files with 18 additions and 24 deletions

View File

@ -147,7 +147,7 @@ export default class MainBackground {
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService); this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
this.totpService = new TotpService(this.storageService, cryptoFunctionService); this.totpService = new TotpService(this.storageService, cryptoFunctionService);
this.autofillService = new AutofillService(this.cipherService, this.tokenService, this.autofillService = new AutofillService(this.cipherService, this.tokenService,
this.totpService, this.utilsService, this.platformUtilsService); this.totpService);
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService); this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
this.auditService = new AuditService(cryptoFunctionService); this.auditService = new AuditService(cryptoFunctionService);
this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService, this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService,

View File

@ -136,11 +136,15 @@ export default class RuntimeBackground {
break; break;
case 'autofiller': case 'autofiller':
case 'autofill_cmd': case 'autofill_cmd':
await this.autofillService.doAutoFillForLastUsedLogin([{ const totpCode = await this.autofillService.doAutoFillForLastUsedLogin([{
frameId: sender.frameId, frameId: sender.frameId,
tab: msg.tab, tab: msg.tab,
details: msg.details, details: msg.details,
}], msg.sender === 'autofill_cmd'); }], msg.sender === 'autofill_cmd');
if (totpCode !== null && !this.platformUtilsService.isFirefox()) {
this.platformUtilsService.copyToClipboard(totpCode);
}
break; break;
case 'contextMenu': case 'contextMenu':
clearTimeout(this.autofillTimeout); clearTimeout(this.autofillTimeout);
@ -161,12 +165,15 @@ export default class RuntimeBackground {
} }
private async autofillPage() { private async autofillPage() {
await this.autofillService.doAutoFill({ const totpCode = await this.autofillService.doAutoFill({
cipher: this.main.loginToAutoFill, cipher: this.main.loginToAutoFill,
pageDetails: this.pageDetailsToAutoFill, pageDetails: this.pageDetailsToAutoFill,
fromBackground: true,
}); });
if (totpCode !== null && !this.platformUtilsService.isFirefox()) {
this.platformUtilsService.copyToClipboard(totpCode);
}
// reset // reset
this.main.loginToAutoFill = null; this.main.loginToAutoFill = null;
this.pageDetailsToAutoFill = []; this.pageDetailsToAutoFill = [];

View File

@ -134,12 +134,11 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
const totpCode = await this.autofillService.doAutoFill({ const totpCode = await this.autofillService.doAutoFill({
cipher: cipher, cipher: cipher,
pageDetails: this.pageDetails, pageDetails: this.pageDetails,
fromBackground: false,
doc: window.document, doc: window.document,
}); });
this.analytics.eventTrack.next({ action: 'Autofilled' }); this.analytics.eventTrack.next({ action: 'Autofilled' });
if (totpCode != null && this.platformUtilsService.isFirefox()) { if (totpCode != null) {
this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document }); this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document });
} }

View File

@ -3,5 +3,5 @@ import AutofillPageDetails from '../../models/autofillPageDetails';
export abstract class AutofillService { export abstract class AutofillService {
getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[]; getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[];
doAutoFill: (options: any) => Promise<string>; doAutoFill: (options: any) => Promise<string>;
doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise<void>; doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise<string>;
} }

View File

@ -105,10 +105,8 @@ var IsoProvinces: { [id: string]: string; } = {
/* tslint:enable */ /* tslint:enable */
export default class AutofillService implements AutofillServiceInterface { export default class AutofillService implements AutofillServiceInterface {
constructor(public cipherService: CipherService, public tokenService: TokenService, constructor(private cipherService: CipherService, private tokenService: TokenService,
public totpService: TotpService, public utilsService: UtilsServiceAbstraction, private totpService: TotpService) { }
public platformUtilsService: PlatformUtilsService) {
}
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
const formData: any[] = []; const formData: any[] = [];
@ -180,8 +178,7 @@ export default class AutofillService implements AutofillServiceInterface {
fillScript: fillScript, fillScript: fillScript,
}, { frameId: pd.frameId }); }, { frameId: pd.frameId });
if (options.cipher.type !== CipherType.Login || totpPromise || if (options.cipher.type !== CipherType.Login || totpPromise || options.skipTotp ||
(options.fromBackground && this.platformUtilsService.isFirefox()) || options.skipTotp ||
!options.cipher.login.totp || !this.tokenService.getPremium()) { !options.cipher.login.totp || !this.tokenService.getPremium()) {
return; return;
} }
@ -190,21 +187,13 @@ export default class AutofillService implements AutofillServiceInterface {
if (enabled) { if (enabled) {
return this.totpService.getCode(options.cipher.login.totp); return this.totpService.getCode(options.cipher.login.totp);
} }
return null; return null;
}).then((code: string) => {
if (code) {
UtilsService.copyToClipboard(code, options.doc);
}
return code;
}); });
}); });
if (didAutofill) { if (didAutofill) {
if (totpPromise != null) { if (totpPromise != null) {
const totpCode = await totpPromise; return await totpPromise;
return totpCode;
} else { } else {
return null; return null;
} }
@ -224,11 +213,10 @@ export default class AutofillService implements AutofillServiceInterface {
return; return;
} }
await this.doAutoFill({ return await this.doAutoFill({
cipher: lastUsedCipher, cipher: lastUsedCipher,
// tslint:disable-next-line // tslint:disable-next-line
pageDetails: pageDetails, pageDetails: pageDetails,
fromBackground: true,
skipTotp: !fromCommand, skipTotp: !fromCommand,
skipLastUsed: true, skipLastUsed: true,
skipUsernameOnlyFill: !fromCommand, skipUsernameOnlyFill: !fromCommand,