From 1f11b7cc3b60e0da6fae1498bb652e8a4c70f173 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Mon, 20 Dec 2021 14:20:58 +1000 Subject: [PATCH] Run Prettier --- angular/src/components/login.component.ts | 7 ++++- .../two-factor-options.component.ts | 2 +- .../src/components/two-factor.component.ts | 12 ++++---- common/src/abstractions/auth.service.ts | 19 ++++++++---- .../src/abstractions/keyConnector.service.ts | 7 ++++- .../identityToken/passwordTokenRequest.ts | 2 +- .../request/identityToken/tokenRequest.ts | 11 +++---- common/src/services/auth.service.ts | 2 +- common/src/services/keyConnector.service.ts | 20 +++++++------ node/src/cli/commands/login.command.ts | 30 +++++++------------ spec/common/services/auth.service.spec.ts | 11 +++---- 11 files changed, 65 insertions(+), 58 deletions(-) diff --git a/angular/src/components/login.component.ts b/angular/src/components/login.component.ts index f9039551..73e972be 100644 --- a/angular/src/components/login.component.ts +++ b/angular/src/components/login.component.ts @@ -93,7 +93,12 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit } 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; if (this.rememberEmail) { await this.stateService.setRememberedEmail(this.email); diff --git a/angular/src/components/two-factor-options.component.ts b/angular/src/components/two-factor-options.component.ts index 46b1db1a..ddf3d2f3 100644 --- a/angular/src/components/two-factor-options.component.ts +++ b/angular/src/components/two-factor-options.component.ts @@ -6,7 +6,7 @@ import { TwoFactorProviderType } from "jslib-common/enums/twoFactorProviderType" import { AuthService } from "jslib-common/abstractions/auth.service"; import { I18nService } from "jslib-common/abstractions/i18n.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() export class TwoFactorOptionsComponent implements OnInit { diff --git a/angular/src/components/two-factor.component.ts b/angular/src/components/two-factor.component.ts index 2e5c887f..69c591cb 100644 --- a/angular/src/components/two-factor.component.ts +++ b/angular/src/components/two-factor.component.ts @@ -192,13 +192,11 @@ export class TwoFactorComponent implements OnInit, OnDestroy { } async doSubmit() { - this.formPromise = this.authService.logInTwoFactor( - { - provider: this.selectedProviderType, - token: this.token, - remember: this.remember - } - ); + this.formPromise = this.authService.logInTwoFactor({ + provider: this.selectedProviderType, + token: this.token, + remember: this.remember, + }); const response: AuthResult = await this.formPromise; const disableFavicon = await this.stateService.getDisableFavicon(); await this.stateService.setDisableFavicon(!!disableFavicon); diff --git a/common/src/abstractions/auth.service.ts b/common/src/abstractions/auth.service.ts index cd1db92b..fe376737 100644 --- a/common/src/abstractions/auth.service.ts +++ b/common/src/abstractions/auth.service.ts @@ -1,20 +1,27 @@ import { AuthResult } from "../models/domain/authResult"; import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey"; -import { TwoFactorData } from '../models/request/identityToken/tokenRequest'; +import { TwoFactorData } from "../models/request/identityToken/tokenRequest"; export abstract class AuthService { - logIn: (email: string, masterPassword: string, twoFactor?: TwoFactorData, captchaToken?: string) => Promise; + logIn: ( + email: string, + masterPassword: string, + twoFactor?: TwoFactorData, + captchaToken?: string + ) => Promise; logInSso: ( code: string, codeVerifier: string, redirectUrl: string, orgId: string, - twoFactor?: TwoFactorData, + twoFactor?: TwoFactorData ) => Promise; - logInApiKey: (clientId: string, clientSecret: string, twoFactor?: TwoFactorData) => Promise; - logInTwoFactor: ( - twoFactor: TwoFactorData + logInApiKey: ( + clientId: string, + clientSecret: string, + twoFactor?: TwoFactorData ) => Promise; + logInTwoFactor: (twoFactor: TwoFactorData) => Promise; logOut: (callback: Function) => void; makePreloginKey: (masterPassword: string, email: string) => Promise; authingWithApiKey: () => boolean; diff --git a/common/src/abstractions/keyConnector.service.ts b/common/src/abstractions/keyConnector.service.ts index db2392ff..0705f27d 100644 --- a/common/src/abstractions/keyConnector.service.ts +++ b/common/src/abstractions/keyConnector.service.ts @@ -6,7 +6,12 @@ export abstract class KeyConnectorService { getUsesKeyConnector: () => Promise; migrateUser: () => Promise; userNeedsMigration: () => Promise; - convertNewSsoUserToKeyConnector: (kdf: number, kdfIterations: number, url: string, orgId: string) => void; + convertNewSsoUserToKeyConnector: ( + kdf: number, + kdfIterations: number, + url: string, + orgId: string + ) => void; setUsesKeyConnector: (enabled: boolean) => Promise; setConvertAccountRequired: (status: boolean) => Promise; getConvertAccountRequired: () => Promise; diff --git a/common/src/models/request/identityToken/passwordTokenRequest.ts b/common/src/models/request/identityToken/passwordTokenRequest.ts index 14cf1a78..5dc5261d 100644 --- a/common/src/models/request/identityToken/passwordTokenRequest.ts +++ b/common/src/models/request/identityToken/passwordTokenRequest.ts @@ -1,6 +1,6 @@ import { TokenRequest, TwoFactorData } from "./tokenRequest"; -import { CaptchaProtectedRequest } from '../captchaProtectedRequest'; +import { CaptchaProtectedRequest } from "../captchaProtectedRequest"; import { DeviceRequest } from "../deviceRequest"; import { Utils } from "../../../misc/utils"; diff --git a/common/src/models/request/identityToken/tokenRequest.ts b/common/src/models/request/identityToken/tokenRequest.ts index 1399a023..588ab30b 100644 --- a/common/src/models/request/identityToken/tokenRequest.ts +++ b/common/src/models/request/identityToken/tokenRequest.ts @@ -12,10 +12,7 @@ export interface TwoFactorData { export abstract class TokenRequest { protected device?: DeviceRequest; - constructor( - protected twoFactor: TwoFactorData, - device?: DeviceRequest - ) { + constructor(protected twoFactor: TwoFactorData, device?: DeviceRequest) { this.device = device != null ? device : null; } @@ -46,7 +43,7 @@ export abstract class TokenRequest { // Implemented in subclass if required } - setTwoFactor(twoFactor: TwoFactorData) { - this.twoFactor = twoFactor; - } + setTwoFactor(twoFactor: TwoFactorData) { + this.twoFactor = twoFactor; + } } diff --git a/common/src/services/auth.service.ts b/common/src/services/auth.service.ts index 5f4fb9f3..3d8f7ef9 100644 --- a/common/src/services/auth.service.ts +++ b/common/src/services/auth.service.ts @@ -264,7 +264,7 @@ export class AuthService implements AuthServiceAbstraction { private async processTokenResponse( response: IdentityTokenResponse | IdentityTwoFactorResponse | IdentityCaptchaResponse, - newSsoUser: boolean = false, + newSsoUser: boolean = false ): Promise { this.clearState(); const result = new AuthResult(); diff --git a/common/src/services/keyConnector.service.ts b/common/src/services/keyConnector.service.ts index 431984fe..c46631f8 100644 --- a/common/src/services/keyConnector.service.ts +++ b/common/src/services/keyConnector.service.ts @@ -1,6 +1,6 @@ import { ApiService } from "../abstractions/api.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 { LogService } from "../abstractions/log.service"; import { OrganizationService } from "../abstractions/organization.service"; @@ -12,10 +12,10 @@ import { OrganizationUserType } from "../enums/organizationUserType"; import { Utils } from "../misc/utils"; 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 { KeysRequest } from '../models/request/keysRequest'; +import { KeysRequest } from "../models/request/keysRequest"; export class KeyConnectorService implements KeyConnectorServiceAbstraction { constructor( @@ -25,7 +25,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { private tokenService: TokenService, private logService: LogService, private organizationService: OrganizationService, - private cryptoFunctionService: CryptoFunctionService, + private cryptoFunctionService: CryptoFunctionService ) {} 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 k = await this.cryptoService.makeKey( @@ -102,10 +107,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { const [pubKey, privKey] = await this.cryptoService.makeKeyPair(); try { - await this.apiService.postUserKeyToKeyConnector( - url, - keyConnectorRequest - ); + await this.apiService.postUserKeyToKeyConnector(url, keyConnectorRequest); } catch (e) { throw new Error("Unable to reach key connector"); } diff --git a/node/src/cli/commands/login.command.ts b/node/src/cli/commands/login.command.ts index 3fa9ca68..d70eb93f 100644 --- a/node/src/cli/commands/login.command.ts +++ b/node/src/cli/commands/login.command.ts @@ -157,37 +157,29 @@ export class LoginCommand { let response: AuthResult = null; if (clientId != null && clientSecret != null) { - response = await this.authService.logInApiKey( - clientId, - clientSecret, - { - provider: twoFactorMethod, - token: twoFactorToken, - remember: false - } - ); + response = await this.authService.logInApiKey(clientId, clientSecret, { + provider: twoFactorMethod, + token: twoFactorToken, + remember: false, + }); } else if (ssoCode != null && ssoCodeVerifier != null) { response = await this.authService.logInSso( ssoCode, ssoCodeVerifier, this.ssoRedirectUri, orgIdentifier, - { - provider: twoFactorMethod, - token: twoFactorToken, - remember: false - } - ); - } else { - response = await this.authService.logIn( - email, - password, { provider: twoFactorMethod, token: twoFactorToken, remember: false, } ); + } else { + response = await this.authService.logIn(email, password, { + provider: twoFactorMethod, + token: twoFactorToken, + remember: false, + }); } if (response.captchaSiteKey) { const badCaptcha = Response.badRequest( diff --git a/spec/common/services/auth.service.spec.ts b/spec/common/services/auth.service.spec.ts index 127bb209..beb514c1 100644 --- a/spec/common/services/auth.service.spec.ts +++ b/spec/common/services/auth.service.spec.ts @@ -507,7 +507,9 @@ describe("Cipher Service", () => { const result = await authService.logInSso(ssoCode, ssoCodeVerifier, ssoRedirectUrl, ssoOrgId); commonSuccessAssertions(); - keyConnectorService.received(1).convertNewSsoUserToKeyConnector(kdf, kdfIterations, keyConnectorUrl, ssoOrgId); + keyConnectorService + .received(1) + .convertNewSsoUserToKeyConnector(kdf, kdfIterations, keyConnectorUrl, ssoOrgId); }); // API @@ -534,11 +536,10 @@ describe("Cipher Service", () => { }) ); - // Sets local environment: - stateService.received(1).setApiKeyClientId(apiClientId); - stateService.received(1).setApiKeyClientSecret(apiClientSecret); - commonSuccessAssertions(); + stateService.received(1).setApiKeyClientId(apiClientId); + stateService.received(1).setApiKeyClientSecret(apiClientSecret); + commonSuccessAssertions(); cryptoService.received(1).setEncKey(encKey); cryptoService.received(1).setEncPrivateKey(privateKey);