mirror of
https://github.com/bitwarden/jslib
synced 2025-12-18 17:23:30 +00:00
Run Prettier
This commit is contained in:
@@ -93,7 +93,12 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.formPromise = this.authService.logIn(this.email, this.masterPassword, null, this.captchaToken);
|
this.formPromise = this.authService.logIn(
|
||||||
|
this.email,
|
||||||
|
this.masterPassword,
|
||||||
|
null,
|
||||||
|
this.captchaToken
|
||||||
|
);
|
||||||
const response = await this.formPromise;
|
const response = await this.formPromise;
|
||||||
if (this.rememberEmail) {
|
if (this.rememberEmail) {
|
||||||
await this.stateService.setRememberedEmail(this.email);
|
await this.stateService.setRememberedEmail(this.email);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { TwoFactorProviderType } from "jslib-common/enums/twoFactorProviderType"
|
|||||||
import { AuthService } from "jslib-common/abstractions/auth.service";
|
import { AuthService } from "jslib-common/abstractions/auth.service";
|
||||||
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
||||||
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
||||||
import { TwoFactorService } from 'jslib-common/abstractions/twoFactor.service';
|
import { TwoFactorService } from "jslib-common/abstractions/twoFactor.service";
|
||||||
|
|
||||||
@Directive()
|
@Directive()
|
||||||
export class TwoFactorOptionsComponent implements OnInit {
|
export class TwoFactorOptionsComponent implements OnInit {
|
||||||
|
|||||||
@@ -192,13 +192,11 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async doSubmit() {
|
async doSubmit() {
|
||||||
this.formPromise = this.authService.logInTwoFactor(
|
this.formPromise = this.authService.logInTwoFactor({
|
||||||
{
|
provider: this.selectedProviderType,
|
||||||
provider: this.selectedProviderType,
|
token: this.token,
|
||||||
token: this.token,
|
remember: this.remember,
|
||||||
remember: this.remember
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
const response: AuthResult = await this.formPromise;
|
const response: AuthResult = await this.formPromise;
|
||||||
const disableFavicon = await this.stateService.getDisableFavicon();
|
const disableFavicon = await this.stateService.getDisableFavicon();
|
||||||
await this.stateService.setDisableFavicon(!!disableFavicon);
|
await this.stateService.setDisableFavicon(!!disableFavicon);
|
||||||
|
|||||||
@@ -1,20 +1,27 @@
|
|||||||
import { AuthResult } from "../models/domain/authResult";
|
import { AuthResult } from "../models/domain/authResult";
|
||||||
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
|
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
|
||||||
import { TwoFactorData } from '../models/request/identityToken/tokenRequest';
|
import { TwoFactorData } from "../models/request/identityToken/tokenRequest";
|
||||||
|
|
||||||
export abstract class AuthService {
|
export abstract class AuthService {
|
||||||
logIn: (email: string, masterPassword: string, twoFactor?: TwoFactorData, captchaToken?: string) => Promise<AuthResult>;
|
logIn: (
|
||||||
|
email: string,
|
||||||
|
masterPassword: string,
|
||||||
|
twoFactor?: TwoFactorData,
|
||||||
|
captchaToken?: string
|
||||||
|
) => Promise<AuthResult>;
|
||||||
logInSso: (
|
logInSso: (
|
||||||
code: string,
|
code: string,
|
||||||
codeVerifier: string,
|
codeVerifier: string,
|
||||||
redirectUrl: string,
|
redirectUrl: string,
|
||||||
orgId: string,
|
orgId: string,
|
||||||
twoFactor?: TwoFactorData,
|
twoFactor?: TwoFactorData
|
||||||
) => Promise<AuthResult>;
|
) => Promise<AuthResult>;
|
||||||
logInApiKey: (clientId: string, clientSecret: string, twoFactor?: TwoFactorData) => Promise<AuthResult>;
|
logInApiKey: (
|
||||||
logInTwoFactor: (
|
clientId: string,
|
||||||
twoFactor: TwoFactorData
|
clientSecret: string,
|
||||||
|
twoFactor?: TwoFactorData
|
||||||
) => Promise<AuthResult>;
|
) => Promise<AuthResult>;
|
||||||
|
logInTwoFactor: (twoFactor: TwoFactorData) => Promise<AuthResult>;
|
||||||
logOut: (callback: Function) => void;
|
logOut: (callback: Function) => void;
|
||||||
makePreloginKey: (masterPassword: string, email: string) => Promise<SymmetricCryptoKey>;
|
makePreloginKey: (masterPassword: string, email: string) => Promise<SymmetricCryptoKey>;
|
||||||
authingWithApiKey: () => boolean;
|
authingWithApiKey: () => boolean;
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ export abstract class KeyConnectorService {
|
|||||||
getUsesKeyConnector: () => Promise<boolean>;
|
getUsesKeyConnector: () => Promise<boolean>;
|
||||||
migrateUser: () => Promise<void>;
|
migrateUser: () => Promise<void>;
|
||||||
userNeedsMigration: () => Promise<boolean>;
|
userNeedsMigration: () => Promise<boolean>;
|
||||||
convertNewSsoUserToKeyConnector: (kdf: number, kdfIterations: number, url: string, orgId: string) => void;
|
convertNewSsoUserToKeyConnector: (
|
||||||
|
kdf: number,
|
||||||
|
kdfIterations: number,
|
||||||
|
url: string,
|
||||||
|
orgId: string
|
||||||
|
) => void;
|
||||||
setUsesKeyConnector: (enabled: boolean) => Promise<void>;
|
setUsesKeyConnector: (enabled: boolean) => Promise<void>;
|
||||||
setConvertAccountRequired: (status: boolean) => Promise<void>;
|
setConvertAccountRequired: (status: boolean) => Promise<void>;
|
||||||
getConvertAccountRequired: () => Promise<boolean>;
|
getConvertAccountRequired: () => Promise<boolean>;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { TokenRequest, TwoFactorData } from "./tokenRequest";
|
import { TokenRequest, TwoFactorData } from "./tokenRequest";
|
||||||
|
|
||||||
import { CaptchaProtectedRequest } from '../captchaProtectedRequest';
|
import { CaptchaProtectedRequest } from "../captchaProtectedRequest";
|
||||||
import { DeviceRequest } from "../deviceRequest";
|
import { DeviceRequest } from "../deviceRequest";
|
||||||
|
|
||||||
import { Utils } from "../../../misc/utils";
|
import { Utils } from "../../../misc/utils";
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ export interface TwoFactorData {
|
|||||||
export abstract class TokenRequest {
|
export abstract class TokenRequest {
|
||||||
protected device?: DeviceRequest;
|
protected device?: DeviceRequest;
|
||||||
|
|
||||||
constructor(
|
constructor(protected twoFactor: TwoFactorData, device?: DeviceRequest) {
|
||||||
protected twoFactor: TwoFactorData,
|
|
||||||
device?: DeviceRequest
|
|
||||||
) {
|
|
||||||
this.device = device != null ? device : null;
|
this.device = device != null ? device : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +43,7 @@ export abstract class TokenRequest {
|
|||||||
// Implemented in subclass if required
|
// Implemented in subclass if required
|
||||||
}
|
}
|
||||||
|
|
||||||
setTwoFactor(twoFactor: TwoFactorData) {
|
setTwoFactor(twoFactor: TwoFactorData) {
|
||||||
this.twoFactor = twoFactor;
|
this.twoFactor = twoFactor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ export class AuthService implements AuthServiceAbstraction {
|
|||||||
|
|
||||||
private async processTokenResponse(
|
private async processTokenResponse(
|
||||||
response: IdentityTokenResponse | IdentityTwoFactorResponse | IdentityCaptchaResponse,
|
response: IdentityTokenResponse | IdentityTwoFactorResponse | IdentityCaptchaResponse,
|
||||||
newSsoUser: boolean = false,
|
newSsoUser: boolean = false
|
||||||
): Promise<AuthResult> {
|
): Promise<AuthResult> {
|
||||||
this.clearState();
|
this.clearState();
|
||||||
const result = new AuthResult();
|
const result = new AuthResult();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ApiService } from "../abstractions/api.service";
|
import { ApiService } from "../abstractions/api.service";
|
||||||
import { CryptoService } from "../abstractions/crypto.service";
|
import { CryptoService } from "../abstractions/crypto.service";
|
||||||
import { CryptoFunctionService } from '../abstractions/cryptoFunction.service';
|
import { CryptoFunctionService } from "../abstractions/cryptoFunction.service";
|
||||||
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "../abstractions/keyConnector.service";
|
import { KeyConnectorService as KeyConnectorServiceAbstraction } from "../abstractions/keyConnector.service";
|
||||||
import { LogService } from "../abstractions/log.service";
|
import { LogService } from "../abstractions/log.service";
|
||||||
import { OrganizationService } from "../abstractions/organization.service";
|
import { OrganizationService } from "../abstractions/organization.service";
|
||||||
@@ -12,10 +12,10 @@ import { OrganizationUserType } from "../enums/organizationUserType";
|
|||||||
import { Utils } from "../misc/utils";
|
import { Utils } from "../misc/utils";
|
||||||
|
|
||||||
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
|
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
|
||||||
import { SetKeyConnectorKeyRequest } from '../models/request/account/setKeyConnectorKeyRequest';
|
import { SetKeyConnectorKeyRequest } from "../models/request/account/setKeyConnectorKeyRequest";
|
||||||
|
|
||||||
import { KeyConnectorUserKeyRequest } from "../models/request/keyConnectorUserKeyRequest";
|
import { KeyConnectorUserKeyRequest } from "../models/request/keyConnectorUserKeyRequest";
|
||||||
import { KeysRequest } from '../models/request/keysRequest';
|
import { KeysRequest } from "../models/request/keysRequest";
|
||||||
|
|
||||||
export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -25,7 +25,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
|||||||
private tokenService: TokenService,
|
private tokenService: TokenService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private organizationService: OrganizationService,
|
private organizationService: OrganizationService,
|
||||||
private cryptoFunctionService: CryptoFunctionService,
|
private cryptoFunctionService: CryptoFunctionService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
setUsesKeyConnector(usesKeyConnector: boolean) {
|
setUsesKeyConnector(usesKeyConnector: boolean) {
|
||||||
@@ -84,7 +84,12 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async convertNewSsoUserToKeyConnector(kdf: number, kdfIterations: number, url: string, orgId: string) {
|
async convertNewSsoUserToKeyConnector(
|
||||||
|
kdf: number,
|
||||||
|
kdfIterations: number,
|
||||||
|
url: string,
|
||||||
|
orgId: string
|
||||||
|
) {
|
||||||
const password = await this.cryptoFunctionService.randomBytes(64);
|
const password = await this.cryptoFunctionService.randomBytes(64);
|
||||||
|
|
||||||
const k = await this.cryptoService.makeKey(
|
const k = await this.cryptoService.makeKey(
|
||||||
@@ -102,10 +107,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction {
|
|||||||
const [pubKey, privKey] = await this.cryptoService.makeKeyPair();
|
const [pubKey, privKey] = await this.cryptoService.makeKeyPair();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.apiService.postUserKeyToKeyConnector(
|
await this.apiService.postUserKeyToKeyConnector(url, keyConnectorRequest);
|
||||||
url,
|
|
||||||
keyConnectorRequest
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("Unable to reach key connector");
|
throw new Error("Unable to reach key connector");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,37 +157,29 @@ export class LoginCommand {
|
|||||||
|
|
||||||
let response: AuthResult = null;
|
let response: AuthResult = null;
|
||||||
if (clientId != null && clientSecret != null) {
|
if (clientId != null && clientSecret != null) {
|
||||||
response = await this.authService.logInApiKey(
|
response = await this.authService.logInApiKey(clientId, clientSecret, {
|
||||||
clientId,
|
provider: twoFactorMethod,
|
||||||
clientSecret,
|
token: twoFactorToken,
|
||||||
{
|
remember: false,
|
||||||
provider: twoFactorMethod,
|
});
|
||||||
token: twoFactorToken,
|
|
||||||
remember: false
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if (ssoCode != null && ssoCodeVerifier != null) {
|
} else if (ssoCode != null && ssoCodeVerifier != null) {
|
||||||
response = await this.authService.logInSso(
|
response = await this.authService.logInSso(
|
||||||
ssoCode,
|
ssoCode,
|
||||||
ssoCodeVerifier,
|
ssoCodeVerifier,
|
||||||
this.ssoRedirectUri,
|
this.ssoRedirectUri,
|
||||||
orgIdentifier,
|
orgIdentifier,
|
||||||
{
|
|
||||||
provider: twoFactorMethod,
|
|
||||||
token: twoFactorToken,
|
|
||||||
remember: false
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
response = await this.authService.logIn(
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
{
|
{
|
||||||
provider: twoFactorMethod,
|
provider: twoFactorMethod,
|
||||||
token: twoFactorToken,
|
token: twoFactorToken,
|
||||||
remember: false,
|
remember: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
response = await this.authService.logIn(email, password, {
|
||||||
|
provider: twoFactorMethod,
|
||||||
|
token: twoFactorToken,
|
||||||
|
remember: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (response.captchaSiteKey) {
|
if (response.captchaSiteKey) {
|
||||||
const badCaptcha = Response.badRequest(
|
const badCaptcha = Response.badRequest(
|
||||||
|
|||||||
@@ -507,7 +507,9 @@ describe("Cipher Service", () => {
|
|||||||
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId);
|
const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId);
|
||||||
|
|
||||||
commonSuccessAssertions();
|
commonSuccessAssertions();
|
||||||
keyConnectorService.received(1).convertNewSsoUserToKeyConnector(kdf, kdfIterations, keyConnectorUrl, ssoOrgId);
|
keyConnectorService
|
||||||
|
.received(1)
|
||||||
|
.convertNewSsoUserToKeyConnector(kdf, kdfIterations, keyConnectorUrl, ssoOrgId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// API
|
// API
|
||||||
@@ -534,11 +536,10 @@ describe("Cipher Service", () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Sets local environment:
|
// Sets local environment:
|
||||||
stateService.received(1).setApiKeyClientId(apiClientId);
|
stateService.received(1).setApiKeyClientId(apiClientId);
|
||||||
stateService.received(1).setApiKeyClientSecret(apiClientSecret);
|
stateService.received(1).setApiKeyClientSecret(apiClientSecret);
|
||||||
commonSuccessAssertions();
|
commonSuccessAssertions();
|
||||||
|
|
||||||
cryptoService.received(1).setEncKey(encKey);
|
cryptoService.received(1).setEncKey(encKey);
|
||||||
cryptoService.received(1).setEncPrivateKey(privateKey);
|
cryptoService.received(1).setEncPrivateKey(privateKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user