mirror of
https://github.com/bitwarden/jslib
synced 2025-12-12 06:13:29 +00:00
Extract createKeyPair to own method
This commit is contained in:
@@ -365,31 +365,41 @@ export class AuthService implements AuthServiceAbstraction {
|
|||||||
await this.apiService.postSetKeyConnectorKey(setPasswordRequest);
|
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);
|
const accountInformation = await this.tokenService.decodeToken(tokenResponse.accessToken);
|
||||||
await this.stateService.addAccount({
|
await this.stateService.addAccount({
|
||||||
profile: {
|
profile: {
|
||||||
...new AccountProfile(),
|
...new AccountProfile(),
|
||||||
...{
|
...{
|
||||||
userId: accountInformation.sub,
|
userId: accountInformation.sub,
|
||||||
email: accountInformation.email,
|
email: accountInformation.email,
|
||||||
apiKeyClientId: clientId,
|
apiKeyClientId: clientId,
|
||||||
apiKeyClientSecret: clientSecret,
|
apiKeyClientSecret: clientSecret,
|
||||||
hasPremiumPersonally: accountInformation.premium,
|
hasPremiumPersonally: accountInformation.premium,
|
||||||
kdfIterations: tokenResponse.kdfIterations,
|
kdfIterations: tokenResponse.kdfIterations,
|
||||||
kdfType: tokenResponse.kdf,
|
kdfType: tokenResponse.kdf,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
tokens: {
|
||||||
tokens: {
|
...new AccountTokens(),
|
||||||
...new AccountTokens(),
|
...{
|
||||||
...{
|
accessToken: tokenResponse.accessToken,
|
||||||
accessToken: tokenResponse.accessToken,
|
refreshToken: tokenResponse.refreshToken,
|
||||||
refreshToken: tokenResponse.refreshToken,
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
await this.cryptoService.setEncPrivateKey(tokenResponse.privateKey);
|
||||||
} catch (e) {
|
|
||||||
this.logService.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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