1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00

[PM-8524] Introduce TotpCaptureService and the Browser implementation

This commit is contained in:
Shane Melton
2024-07-09 16:40:45 -07:00
parent afd63c8701
commit 8d08bf797a
5 changed files with 68 additions and 5 deletions

View File

@@ -17,11 +17,13 @@ import {
CipherFormMode,
CipherFormModule,
DefaultCipherFormConfigService,
TotpCaptureService,
} from "@bitwarden/vault";
import { PopupFooterComponent } from "../../../../../platform/popup/layout/popup-footer.component";
import { PopupHeaderComponent } from "../../../../../platform/popup/layout/popup-header.component";
import { PopupPageComponent } from "../../../../../platform/popup/layout/popup-page.component";
import { BrowserTotpCaptureService } from "../../../services/browser-totp-capture.service";
import { OpenAttachmentsComponent } from "../attachments/open-attachments/open-attachments.component";
/**
@@ -80,7 +82,10 @@ export type AddEditQueryParams = Partial<Record<keyof QueryParams, string>>;
selector: "app-add-edit-v2",
templateUrl: "add-edit-v2.component.html",
standalone: true,
providers: [{ provide: CipherFormConfigService, useClass: DefaultCipherFormConfigService }],
providers: [
{ provide: CipherFormConfigService, useClass: DefaultCipherFormConfigService },
{ provide: TotpCaptureService, useClass: BrowserTotpCaptureService },
],
imports: [
CommonModule,
SearchModule,

View File

@@ -0,0 +1,23 @@
import { Injectable } from "@angular/core";
import qrcodeParser from "qrcode-parser";
import { TotpCaptureService } from "@bitwarden/vault";
import { BrowserApi } from "../../../platform/browser/browser-api";
/**
* Implementation of TotpCaptureService for the browser which captures the
* TOTP secret from the currently visible tab.
*/
@Injectable()
export class BrowserTotpCaptureService implements TotpCaptureService {
async captureTotpSecret() {
const screenshot = await BrowserApi.captureVisibleTab();
const data = await qrcodeParser(screenshot);
const url = new URL(data.toString());
if (url.protocol === "otpauth:" && url.searchParams.has("secret")) {
return data.toString();
}
return null;
}
}