mirror of
https://github.com/bitwarden/jslib
synced 2025-12-10 21:33:17 +00:00
Extract createKeyPair to own method
This commit is contained in:
@@ -365,7 +365,7 @@ export class AuthService implements AuthServiceAbstraction {
|
||||
await this.apiService.postSetKeyConnectorKey(setPasswordRequest);
|
||||
}
|
||||
|
||||
private async saveAccountInformation(tokenResponse: IdentityTokenResponse, clientId: string, clientSecret: string) {
|
||||
private async saveAccountInformation(tokenResponse: IdentityTokenResponse, clientId: string, clientSecret: string) {
|
||||
const accountInformation = await this.tokenService.decodeToken(tokenResponse.accessToken);
|
||||
await this.stateService.addAccount({
|
||||
profile: {
|
||||
@@ -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,
|
||||
codeVerifier: string, redirectUrl: string, clientId: string, clientSecret: string, key: SymmetricCryptoKey,
|
||||
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
|
||||
if (tokenResponse.privateKey == null) {
|
||||
try {
|
||||
const keyPair = await this.cryptoService.makeKeyPair();
|
||||
await this.apiService.postAccountKeys(new KeysRequest(keyPair[0], keyPair[1].encryptedString));
|
||||
tokenResponse.privateKey = keyPair[1].encryptedString;
|
||||
} catch (e) {
|
||||
this.logService.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
const newKeyPair = await this.createKeyPair();
|
||||
await this.cryptoService.setEncPrivateKey(newKeyPair);
|
||||
} else {
|
||||
await this.cryptoService.setEncPrivateKey(tokenResponse.privateKey);
|
||||
}
|
||||
} else if (tokenResponse.keyConnectorUrl != null) {
|
||||
await this.convertNewUserToKeyConnector(tokenResponse, orgId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user