mirror of
https://github.com/bitwarden/jslib
synced 2025-12-19 09:43:28 +00:00
Update clients to use new authService interface
This commit is contained in:
@@ -93,7 +93,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
||||
}
|
||||
|
||||
try {
|
||||
this.formPromise = this.authService.logIn(this.email, this.masterPassword, this.captchaToken);
|
||||
this.formPromise = this.authService.logIn(this.email, this.masterPassword, null, this.captchaToken);
|
||||
const response = await this.formPromise;
|
||||
if (this.rememberEmail) {
|
||||
await this.stateService.setRememberedEmail(this.email);
|
||||
|
||||
@@ -193,9 +193,11 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
|
||||
|
||||
async doSubmit() {
|
||||
this.formPromise = this.authService.logInTwoFactor(
|
||||
this.selectedProviderType,
|
||||
this.token,
|
||||
this.remember
|
||||
{
|
||||
provider: this.selectedProviderType,
|
||||
token: this.token,
|
||||
remember: this.remember
|
||||
}
|
||||
);
|
||||
const response: AuthResult = await this.formPromise;
|
||||
const disableFavicon = await this.stateService.getDisableFavicon();
|
||||
|
||||
@@ -11,15 +11,15 @@ export abstract class AuthService {
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
|
||||
logIn: (email: string, masterPassword: string, twoFactor: TwoFactorData, captchaToken?: string) => Promise<AuthResult>;
|
||||
logIn: (email: string, masterPassword: string, twoFactor?: TwoFactorData, captchaToken?: string) => Promise<AuthResult>;
|
||||
logInSso: (
|
||||
code: string,
|
||||
codeVerifier: string,
|
||||
redirectUrl: string,
|
||||
twoFactor: TwoFactorData,
|
||||
orgId: string
|
||||
orgId: string,
|
||||
twoFactor?: TwoFactorData,
|
||||
) => Promise<AuthResult>;
|
||||
logInApiKey: (clientId: string, clientSecret: string, twoFactor: TwoFactorData) => Promise<AuthResult>;
|
||||
logInApiKey: (clientId: string, clientSecret: string, twoFactor?: TwoFactorData) => Promise<AuthResult>;
|
||||
logInTwoFactor: (
|
||||
twoFactor: TwoFactorData
|
||||
) => Promise<AuthResult>;
|
||||
|
||||
@@ -65,7 +65,7 @@ export class AuthService implements AuthServiceAbstraction {
|
||||
private setCryptoKeys = true
|
||||
) {}
|
||||
|
||||
async logIn(email: string, masterPassword: string, twoFactor: TwoFactorData, captchaToken?: string): Promise<AuthResult> {
|
||||
async logIn(email: string, masterPassword: string, twoFactor?: TwoFactorData, captchaToken?: string): Promise<AuthResult> {
|
||||
this.twoFactorService.clearSelectedProvider();
|
||||
const key = await this.makePreloginKey(masterPassword, email);
|
||||
const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key);
|
||||
@@ -94,8 +94,8 @@ export class AuthService implements AuthServiceAbstraction {
|
||||
code: string,
|
||||
codeVerifier: string,
|
||||
redirectUrl: string,
|
||||
twoFactor: TwoFactorData,
|
||||
orgId: string
|
||||
orgId: string,
|
||||
twoFactor?: TwoFactorData,
|
||||
): Promise<AuthResult> {
|
||||
this.twoFactorService.clearSelectedProvider();
|
||||
return await this.logInHelper(
|
||||
@@ -114,7 +114,7 @@ export class AuthService implements AuthServiceAbstraction {
|
||||
);
|
||||
}
|
||||
|
||||
async logInApiKey(clientId: string, clientSecret: string, twoFactor: TwoFactorData): Promise<AuthResult> {
|
||||
async logInApiKey(clientId: string, clientSecret: string, twoFactor?: TwoFactorData): Promise<AuthResult> {
|
||||
this.twoFactorService.clearSelectedProvider();
|
||||
return await this.logInHelper(
|
||||
null,
|
||||
|
||||
@@ -156,46 +156,38 @@ export class LoginCommand {
|
||||
}
|
||||
|
||||
let response: AuthResult = null;
|
||||
if (twoFactorToken != null && twoFactorMethod != null) {
|
||||
if (clientId != null && clientSecret != null) {
|
||||
response = await this.authService.logInApiKeyComplete(
|
||||
response = await this.authService.logInApiKey(
|
||||
clientId,
|
||||
clientSecret,
|
||||
twoFactorMethod,
|
||||
twoFactorToken,
|
||||
false
|
||||
);
|
||||
} else if (ssoCode != null && ssoCodeVerifier != null) {
|
||||
response = await this.authService.logInSsoComplete(
|
||||
ssoCode,
|
||||
ssoCodeVerifier,
|
||||
this.ssoRedirectUri,
|
||||
twoFactorMethod,
|
||||
twoFactorToken,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
response = await this.authService.logInComplete(
|
||||
email,
|
||||
password,
|
||||
twoFactorMethod,
|
||||
twoFactorToken,
|
||||
false,
|
||||
this.clientSecret
|
||||
);
|
||||
{
|
||||
provider: twoFactorMethod,
|
||||
token: twoFactorToken,
|
||||
remember: false
|
||||
}
|
||||
} else {
|
||||
if (clientId != null && clientSecret != null) {
|
||||
response = await this.authService.logInApiKey(clientId, clientSecret);
|
||||
);
|
||||
} else if (ssoCode != null && ssoCodeVerifier != null) {
|
||||
response = await this.authService.logInSso(
|
||||
ssoCode,
|
||||
ssoCodeVerifier,
|
||||
this.ssoRedirectUri,
|
||||
orgIdentifier
|
||||
orgIdentifier,
|
||||
{
|
||||
provider: twoFactorMethod,
|
||||
token: twoFactorToken,
|
||||
remember: false
|
||||
}
|
||||
);
|
||||
} else {
|
||||
response = await this.authService.logIn(email, password);
|
||||
response = await this.authService.logIn(
|
||||
email,
|
||||
password,
|
||||
{
|
||||
provider: twoFactorMethod,
|
||||
token: twoFactorToken,
|
||||
remember: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
if (response.captchaSiteKey) {
|
||||
const badCaptcha = Response.badRequest(
|
||||
@@ -210,12 +202,14 @@ export class LoginCommand {
|
||||
return badCaptcha;
|
||||
}
|
||||
|
||||
const secondResponse = await this.authService.logInComplete(
|
||||
const secondResponse = await this.authService.logIn(
|
||||
email,
|
||||
password,
|
||||
twoFactorMethod,
|
||||
twoFactorToken,
|
||||
false,
|
||||
{
|
||||
provider: twoFactorMethod,
|
||||
token: twoFactorToken,
|
||||
remember: false,
|
||||
},
|
||||
captchaClientSecret
|
||||
);
|
||||
response = secondResponse;
|
||||
@@ -298,12 +292,11 @@ export class LoginCommand {
|
||||
}
|
||||
}
|
||||
|
||||
response = await this.authService.logInTwoFactor(
|
||||
selectedProvider.type,
|
||||
twoFactorToken,
|
||||
false
|
||||
);
|
||||
}
|
||||
response = await this.authService.logInTwoFactor({
|
||||
provider: selectedProvider.type,
|
||||
token: twoFactorToken,
|
||||
remember: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (response.twoFactor) {
|
||||
|
||||
@@ -190,7 +190,7 @@ describe("Cipher Service", () => {
|
||||
const expected = newAuthResponse();
|
||||
|
||||
// Act
|
||||
const result = await authService.logIn(email, masterPassword, null);
|
||||
const result = await authService.logIn(email, masterPassword);
|
||||
|
||||
// Assert
|
||||
// Api call:
|
||||
@@ -240,7 +240,7 @@ describe("Cipher Service", () => {
|
||||
expected.captchaSiteKey = siteKey;
|
||||
|
||||
// Act
|
||||
const result = await authService.logIn(email, masterPassword, null);
|
||||
const result = await authService.logIn(email, masterPassword);
|
||||
|
||||
// Assertions
|
||||
stateService.didNotReceive().addAccount(Arg.any());
|
||||
@@ -274,7 +274,7 @@ describe("Cipher Service", () => {
|
||||
);
|
||||
|
||||
// Act
|
||||
const result = await authService.logIn(email, masterPassword, null);
|
||||
const result = await authService.logIn(email, masterPassword);
|
||||
|
||||
// Assertions
|
||||
commonSuccessAssertions();
|
||||
@@ -293,7 +293,7 @@ describe("Cipher Service", () => {
|
||||
tokenService.getTwoFactorToken(email).resolves(null);
|
||||
apiService.postIdentityToken(Arg.any()).resolves(tokenResponse);
|
||||
|
||||
const result = await authService.logIn(email, masterPassword, null);
|
||||
const result = await authService.logIn(email, masterPassword);
|
||||
|
||||
commonSuccessAssertions();
|
||||
apiService.received(1).postAccountKeys(Arg.any());
|
||||
@@ -317,7 +317,7 @@ describe("Cipher Service", () => {
|
||||
expected.twoFactorProviders = twoFactorProviders;
|
||||
expected.captchaSiteKey = undefined;
|
||||
|
||||
const result = await authService.logIn(email, masterPassword, null);
|
||||
const result = await authService.logIn(email, masterPassword);
|
||||
|
||||
stateService.didNotReceive().addAccount(Arg.any());
|
||||
messagingService.didNotReceive().send(Arg.any());
|
||||
@@ -331,7 +331,7 @@ describe("Cipher Service", () => {
|
||||
|
||||
tokenService.getTwoFactorToken(email).resolves(twoFactorToken);
|
||||
|
||||
await authService.logIn(email, masterPassword, null);
|
||||
await authService.logIn(email, masterPassword);
|
||||
|
||||
apiService.received(1).postIdentityToken(
|
||||
Arg.is((actual) => {
|
||||
@@ -406,7 +406,7 @@ describe("Cipher Service", () => {
|
||||
tokenService.getTwoFactorToken(null).resolves(null);
|
||||
apiService.postIdentityToken(Arg.any()).resolves(tokenResponse);
|
||||
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, null, ssoOrgId);
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId);
|
||||
|
||||
// Assert
|
||||
// Api call:
|
||||
@@ -452,7 +452,7 @@ describe("Cipher Service", () => {
|
||||
tokenService.getTwoFactorToken(null).resolves(null);
|
||||
apiService.postIdentityToken(Arg.any()).resolves(tokenResponse);
|
||||
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, null, ssoOrgId);
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId);
|
||||
|
||||
// Assert
|
||||
cryptoService.didNotReceive().setEncPrivateKey(privateKey);
|
||||
@@ -466,7 +466,7 @@ describe("Cipher Service", () => {
|
||||
|
||||
apiService.postIdentityToken(Arg.any()).resolves(tokenResponse);
|
||||
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, null, ssoOrgId);
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId);
|
||||
|
||||
commonSuccessAssertions();
|
||||
keyConnectorService.received(1).getAndSetKey(keyConnectorUrl);
|
||||
@@ -500,7 +500,7 @@ describe("Cipher Service", () => {
|
||||
|
||||
apiService.postIdentityToken(Arg.any()).resolves(tokenResponse);
|
||||
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, null, ssoOrgId);
|
||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId);
|
||||
|
||||
commonSuccessAssertions();
|
||||
cryptoService.received(1).setKey(preloginKey);
|
||||
@@ -529,7 +529,7 @@ describe("Cipher Service", () => {
|
||||
const tokenResponse = newTokenResponse();
|
||||
apiService.postIdentityToken(Arg.any()).resolves(tokenResponse);
|
||||
|
||||
const result = await authService.logInApiKey(apiClientId, apiClientSecret, null);
|
||||
const result = await authService.logInApiKey(apiClientId, apiClientSecret);
|
||||
|
||||
apiService.received(1).postIdentityToken(
|
||||
Arg.is((actual) => {
|
||||
|
||||
Reference in New Issue
Block a user