mirror of
https://github.com/bitwarden/web
synced 2026-01-07 19:13:21 +00:00
Move logic to web, remove debug statements
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: e4cd0af2f9...a6482be6b3
@@ -8,6 +8,7 @@ import { MemoryStorageService } from "../../services/memoryStorage.service";
|
||||
import { PasswordRepromptService } from "../../services/passwordReprompt.service";
|
||||
import { StateService } from "../../services/state.service";
|
||||
import { WebPlatformUtilsService } from "../../services/webPlatformUtils.service";
|
||||
import { KeyConnectorService } from "../../services/keyConnector.service";
|
||||
|
||||
import { EventService } from "./event.service";
|
||||
import { ModalService } from "./modal.service";
|
||||
@@ -49,6 +50,7 @@ import { StateService as StateServiceAbstraction } from "jslib-common/abstractio
|
||||
import { StateMigrationService as StateMigrationServiceAbstraction } from "jslib-common/abstractions/stateMigration.service";
|
||||
import { StorageService as StorageServiceAbstraction } from "jslib-common/abstractions/storage.service";
|
||||
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-common/abstractions/vaultTimeout.service";
|
||||
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "jslib-common/abstractions/keyConnector.service";
|
||||
|
||||
import { ThemeType } from "jslib-common/enums/themeType";
|
||||
|
||||
@@ -190,6 +192,10 @@ export function initFactory(
|
||||
provide: PasswordRepromptServiceAbstraction,
|
||||
useClass: PasswordRepromptService,
|
||||
},
|
||||
{
|
||||
provide: KeyConnectorServiceAbstraction,
|
||||
useClass: KeyConnectorService,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class ServicesModule {}
|
||||
|
||||
@@ -50,7 +50,7 @@ async function start() {
|
||||
}
|
||||
|
||||
if (operation === "get") {
|
||||
const getRequest = new Request(keyConnectorUrl.href + "/user-keys", {
|
||||
const getRequest = new Request(keyConnectorUrl.href + "user-keys", {
|
||||
cache: "no-store",
|
||||
method: "GET",
|
||||
headers: new Headers({
|
||||
@@ -68,7 +68,7 @@ async function start() {
|
||||
}
|
||||
success(new KeyConnectorUserKeyResponse(await response.json()));
|
||||
} else if (operation === "post") {
|
||||
const postRequest = new Request(keyConnectorUrl.href + "/user-keys", {
|
||||
const postRequest = new Request(keyConnectorUrl.href + "user-keys", {
|
||||
cache: "no-store",
|
||||
method: "POST",
|
||||
headers: new Headers({
|
||||
@@ -116,7 +116,7 @@ function success(response: KeyConnectorUserKeyResponse) {
|
||||
return;
|
||||
}
|
||||
parent.postMessage(
|
||||
"success|" + response != null && response.key != null ? response.key : "",
|
||||
"success|" + (response != null && response.key != null ? response.key : ""),
|
||||
parentUrl
|
||||
);
|
||||
sentSuccess = true;
|
||||
|
||||
@@ -30,6 +30,12 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#cme_iframe {
|
||||
border: none;
|
||||
height: 0;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.list-group-2fa {
|
||||
.logo-2fa {
|
||||
min-width: 100px;
|
||||
|
||||
66
src/services/keyConnector.service.ts
Normal file
66
src/services/keyConnector.service.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
|
||||
import { ApiService } from "jslib-common/abstractions/api.service";
|
||||
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
||||
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
||||
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
||||
import { LogService } from "jslib-common/abstractions/log.service";
|
||||
import { OrganizationService } from "jslib-common/abstractions/organization.service";
|
||||
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
import { TokenService } from "jslib-common/abstractions/token.service";
|
||||
|
||||
import { CMEIFrame } from "jslib-common/misc/cme_iframe";
|
||||
import { Utils } from "jslib-common/misc/utils";
|
||||
import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey";
|
||||
|
||||
import { KeyConnectorService as BaseKeyConnectorService } from "jslib-common/services/keyConnector.service";
|
||||
|
||||
@Injectable()
|
||||
export class KeyConnectorService extends BaseKeyConnectorService {
|
||||
constructor(
|
||||
stateService: StateService,
|
||||
cryptoService: CryptoService,
|
||||
apiService: ApiService,
|
||||
tokenService: TokenService,
|
||||
logService: LogService,
|
||||
organizationService: OrganizationService,
|
||||
private environmentService: EnvironmentService,
|
||||
private i18nService: I18nService,
|
||||
private platformUtilsService: PlatformUtilsService
|
||||
) {
|
||||
super(stateService, cryptoService, apiService, tokenService, logService, organizationService);
|
||||
}
|
||||
|
||||
async getAndSetKey(url: string): Promise<void> {
|
||||
const el = document.createElement("iframe");
|
||||
el.id = "cme_iframe";
|
||||
document.body.appendChild(el);
|
||||
|
||||
const webVaultUrl = this.environmentService.getWebVaultUrl();
|
||||
|
||||
const promise: Promise<void> = new Promise(async (resolve) => {
|
||||
const iframe = new CMEIFrame(
|
||||
window,
|
||||
webVaultUrl,
|
||||
(key: string) => {
|
||||
const keyArr = Utils.fromB64ToArray(key);
|
||||
const k = new SymmetricCryptoKey(keyArr);
|
||||
this.cryptoService.setKey(k).then(resolve);
|
||||
},
|
||||
(error: string) => {
|
||||
this.platformUtilsService.showToast("error", null, error);
|
||||
},
|
||||
(info: string) => {
|
||||
this.logService.info(info);
|
||||
}
|
||||
);
|
||||
|
||||
iframe.init(await this.apiService.getActiveBearerToken(), url);
|
||||
});
|
||||
|
||||
promise.finally(() => el.remove());
|
||||
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user