mirror of
https://github.com/bitwarden/jslib
synced 2025-12-12 14:23:20 +00:00
Extract createKeyPair to own method
This commit is contained in:
@@ -390,6 +390,16 @@ private async saveAccountInformation(tokenResponse: IdentityTokenResponse, clien
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async createKeyPair() {
|
||||||
|
try {
|
||||||
|
const keyPair = await this.cryptoService.makeKeyPair();
|
||||||
|
await this.apiService.postAccountKeys(new KeysRequest(keyPair[0], keyPair[1].encryptedString));
|
||||||
|
return keyPair[1].encryptedString;
|
||||||
|
} catch (e) {
|
||||||
|
this.logService.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async logInHelper(email: string, hashedPassword: string, localHashedPassword: string, code: string,
|
private async logInHelper(email: string, hashedPassword: string, localHashedPassword: string, code: string,
|
||||||
codeVerifier: string, redirectUrl: string, clientId: string, clientSecret: string, key: SymmetricCryptoKey,
|
codeVerifier: string, redirectUrl: string, clientId: string, clientSecret: string, key: SymmetricCryptoKey,
|
||||||
twoFactorProvider?: TwoFactorProviderType, twoFactorToken?: string, remember?: boolean, captchaToken?: string,
|
twoFactorProvider?: TwoFactorProviderType, twoFactorToken?: string, remember?: boolean, captchaToken?: string,
|
||||||
@@ -449,16 +459,11 @@ private async saveAccountInformation(tokenResponse: IdentityTokenResponse, clien
|
|||||||
|
|
||||||
// User doesn't have a key pair yet (old account), let's generate one for them
|
// User doesn't have a key pair yet (old account), let's generate one for them
|
||||||
if (tokenResponse.privateKey == null) {
|
if (tokenResponse.privateKey == null) {
|
||||||
try {
|
const newKeyPair = await this.createKeyPair();
|
||||||
const keyPair = await this.cryptoService.makeKeyPair();
|
await this.cryptoService.setEncPrivateKey(newKeyPair);
|
||||||
await this.apiService.postAccountKeys(new KeysRequest(keyPair[0], keyPair[1].encryptedString));
|
} else {
|
||||||
tokenResponse.privateKey = keyPair[1].encryptedString;
|
|
||||||
} catch (e) {
|
|
||||||
this.logService.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.cryptoService.setEncPrivateKey(tokenResponse.privateKey);
|
await this.cryptoService.setEncPrivateKey(tokenResponse.privateKey);
|
||||||
|
}
|
||||||
} else if (tokenResponse.keyConnectorUrl != null) {
|
} else if (tokenResponse.keyConnectorUrl != null) {
|
||||||
await this.convertNewUserToKeyConnector(tokenResponse, orgId);
|
await this.convertNewUserToKeyConnector(tokenResponse, orgId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user