1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-11 13:53:22 +00:00

Move keyConnector onboarding logic to entry method

This commit is contained in:
Thomas Rittson
2021-12-20 11:15:35 +10:00
parent c8eb559f06
commit 6227d3a1e9

View File

@@ -88,13 +88,7 @@ export class AuthService implements AuthServiceAbstraction {
const response = await this.apiService.postIdentityToken(tokenRequest); const response = await this.apiService.postIdentityToken(tokenRequest);
const result = await this.processTokenResponse( const result = await this.processTokenResponse(response, null, null, null, null);
response,
null,
null,
null,
null
);
if (!!result.captchaSiteKey) { if (!!result.captchaSiteKey) {
return result; return result;
@@ -106,8 +100,8 @@ export class AuthService implements AuthServiceAbstraction {
} }
if (this.setCryptoKeys) { if (this.setCryptoKeys) {
await this.cryptoService.setKey(key); await this.cryptoService.setKey(key);
await this.cryptoService.setKeyHash(localHashedPassword); await this.cryptoService.setKeyHash(localHashedPassword);
} }
await this.completeLogIn(); await this.completeLogIn();
@@ -123,7 +117,7 @@ export class AuthService implements AuthServiceAbstraction {
): Promise<AuthResult> { ): Promise<AuthResult> {
this.twoFactorService.clearSelectedProvider(); this.twoFactorService.clearSelectedProvider();
let tokenRequest: SsoTokenRequest let tokenRequest: SsoTokenRequest;
if (this.savedTokenRequest == null) { if (this.savedTokenRequest == null) {
tokenRequest = new SsoTokenRequest( tokenRequest = new SsoTokenRequest(
code, code,
@@ -139,13 +133,7 @@ export class AuthService implements AuthServiceAbstraction {
const response = await this.apiService.postIdentityToken(tokenRequest); const response = await this.apiService.postIdentityToken(tokenRequest);
const result = await this.processTokenResponse( const result = await this.processTokenResponse(response, code, null, null, orgId);
response,
code,
null,
null,
orgId
);
if (!!result.captchaSiteKey) { if (!!result.captchaSiteKey) {
return result; return result;
@@ -156,6 +144,18 @@ export class AuthService implements AuthServiceAbstraction {
return result; return result;
} }
const tokenResponse = response as IdentityTokenResponse;
if (tokenResponse.key == null && tokenResponse.keyConnectorUrl != null) {
// user onboarded using SSO needs conversion to key connector
await this.keyConnectorService.convertNewSsoUserToKeyConnector(
tokenResponse.kdf,
tokenResponse.kdfIterations,
tokenResponse.keyConnectorUrl,
orgId
);
}
await this.completeLogIn(); await this.completeLogIn();
return result; return result;
} }
@@ -182,13 +182,7 @@ export class AuthService implements AuthServiceAbstraction {
const response = await this.apiService.postIdentityToken(tokenRequest); const response = await this.apiService.postIdentityToken(tokenRequest);
const result = await this.processTokenResponse( const result = await this.processTokenResponse(response, null, clientId, clientSecret, null);
response,
null,
clientId,
clientSecret,
null
);
if (!!result.captchaSiteKey) { if (!!result.captchaSiteKey) {
return result; return result;
@@ -305,8 +299,6 @@ export class AuthService implements AuthServiceAbstraction {
} else { } else {
await this.cryptoService.setEncPrivateKey(tokenResponse.privateKey); await this.cryptoService.setEncPrivateKey(tokenResponse.privateKey);
} }
} else if (tokenResponse.keyConnectorUrl != null) {
await this.keyConnectorService.convertNewSsoUserToKeyConnector(tokenResponse.kdf, tokenResponse.kdfIterations, tokenResponse.keyConnectorUrl, orgId);
} }
} }
@@ -388,7 +380,7 @@ export class AuthService implements AuthServiceAbstraction {
tokenRequest: ApiTokenRequest | PasswordTokenRequest | SsoTokenRequest, tokenRequest: ApiTokenRequest | PasswordTokenRequest | SsoTokenRequest,
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string }>, twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string }>,
localhashedPassword?: string, localhashedPassword?: string,
key?: SymmetricCryptoKey, key?: SymmetricCryptoKey
) { ) {
this.savedTokenRequest = tokenRequest; this.savedTokenRequest = tokenRequest;
this.twoFactorService.setProviders(twoFactorProviders); this.twoFactorService.setProviders(twoFactorProviders);