From 32ba34eafeb9df9de820b51de1e6bee3dfd159b6 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Wed, 27 Sep 2023 10:32:08 +0200 Subject: [PATCH] [PM-2014] chore: rename everything to `WebauthnLogin` to follow new naming scheme --- apps/web/src/app/auth/core/core.module.ts | 6 +++--- apps/web/src/app/auth/core/services/index.ts | 2 +- .../app/auth/core/services/webauthn-login/index.ts | 1 + .../request/save-credential.request.ts | 7 +++++++ .../webauthn-login-attestation-response.request.ts} | 4 ++-- .../request/webauthn-login-response.request.ts} | 2 +- ...uthn-login-credential-create-options.response.ts} | 2 +- .../response/webauthn-login-credential.response.ts} | 2 +- .../webauthn-login-api.service.ts} | 12 ++++++------ .../webauthn-login.service.spec.ts} | 12 ++++++------ .../webauthn-login.service.ts} | 10 +++++----- .../web/src/app/auth/core/services/webauthn/index.ts | 1 - .../webauthn/request/save-credential.request.ts | 7 ------- .../create-credential-dialog.component.ts | 4 ++-- .../delete-credential-dialog.component.ts | 4 ++-- .../webauthn-login-settings.component.ts | 7 +++++-- 16 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 apps/web/src/app/auth/core/services/webauthn-login/index.ts create mode 100644 apps/web/src/app/auth/core/services/webauthn-login/request/save-credential.request.ts rename apps/web/src/app/auth/core/services/{webauthn/request/webauthn-attestation-response.request.ts => webauthn-login/request/webauthn-login-attestation-response.request.ts} (76%) rename apps/web/src/app/auth/core/services/{webauthn/request/webauthn-response.request.ts => webauthn-login/request/webauthn-login-response.request.ts} (88%) rename apps/web/src/app/auth/core/services/{webauthn/response/credential-create-options.response.ts => webauthn-login/response/webauthn-login-credential-create-options.response.ts} (84%) rename apps/web/src/app/auth/core/services/{webauthn/response/webauthn-credential.response.ts => webauthn-login/response/webauthn-login-credential.response.ts} (83%) rename apps/web/src/app/auth/core/services/{webauthn/webauthn-api.service.ts => webauthn-login/webauthn-login-api.service.ts} (74%) rename apps/web/src/app/auth/core/services/{webauthn/webauthn.service.spec.ts => webauthn-login/webauthn-login.service.spec.ts} (83%) rename apps/web/src/app/auth/core/services/{webauthn/webauthn.service.ts => webauthn-login/webauthn-login.service.ts} (89%) delete mode 100644 apps/web/src/app/auth/core/services/webauthn/index.ts delete mode 100644 apps/web/src/app/auth/core/services/webauthn/request/save-credential.request.ts diff --git a/apps/web/src/app/auth/core/core.module.ts b/apps/web/src/app/auth/core/core.module.ts index ea7654809e0..e196b1c3d76 100644 --- a/apps/web/src/app/auth/core/core.module.ts +++ b/apps/web/src/app/auth/core/core.module.ts @@ -1,10 +1,10 @@ import { NgModule, Optional, SkipSelf } from "@angular/core"; -import { WebauthnApiService } from "./services/webauthn/webauthn-api.service"; -import { WebauthnService } from "./services/webauthn/webauthn.service"; +import { WebauthnLoginApiService } from "./services/webauthn-login/webauthn-login-api.service"; +import { WebauthnLoginService } from "./services/webauthn-login/webauthn-login.service"; @NgModule({ - providers: [WebauthnService, WebauthnApiService], + providers: [WebauthnLoginService, WebauthnLoginApiService], }) export class CoreAuthModule { constructor(@Optional() @SkipSelf() parentModule?: CoreAuthModule) { diff --git a/apps/web/src/app/auth/core/services/index.ts b/apps/web/src/app/auth/core/services/index.ts index 184c6681b43..4ef20f4b97d 100644 --- a/apps/web/src/app/auth/core/services/index.ts +++ b/apps/web/src/app/auth/core/services/index.ts @@ -1 +1 @@ -export * from "./webauthn"; +export * from "./webauthn-login"; diff --git a/apps/web/src/app/auth/core/services/webauthn-login/index.ts b/apps/web/src/app/auth/core/services/webauthn-login/index.ts new file mode 100644 index 00000000000..10dea636b8d --- /dev/null +++ b/apps/web/src/app/auth/core/services/webauthn-login/index.ts @@ -0,0 +1 @@ +export * from "./webauthn-login.service"; diff --git a/apps/web/src/app/auth/core/services/webauthn-login/request/save-credential.request.ts b/apps/web/src/app/auth/core/services/webauthn-login/request/save-credential.request.ts new file mode 100644 index 00000000000..2ab5feb22fe --- /dev/null +++ b/apps/web/src/app/auth/core/services/webauthn-login/request/save-credential.request.ts @@ -0,0 +1,7 @@ +import { WebauthnLoginResponseRequest } from "./webauthn-login-response.request"; + +export class SaveCredentialRequest { + deviceResponse: WebauthnLoginResponseRequest; + name: string; + token: string; +} diff --git a/apps/web/src/app/auth/core/services/webauthn/request/webauthn-attestation-response.request.ts b/apps/web/src/app/auth/core/services/webauthn-login/request/webauthn-login-attestation-response.request.ts similarity index 76% rename from apps/web/src/app/auth/core/services/webauthn/request/webauthn-attestation-response.request.ts rename to apps/web/src/app/auth/core/services/webauthn-login/request/webauthn-login-attestation-response.request.ts index 7ef5f868984..91922f420ae 100644 --- a/apps/web/src/app/auth/core/services/webauthn/request/webauthn-attestation-response.request.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/request/webauthn-login-attestation-response.request.ts @@ -1,8 +1,8 @@ import { Utils } from "@bitwarden/common/platform/misc/utils"; -import { WebauthnResponseRequest } from "./webauthn-response.request"; +import { WebauthnLoginResponseRequest } from "./webauthn-login-response.request"; -export class WebauthnAttestationResponseRequest extends WebauthnResponseRequest { +export class WebauthnLoginAttestationResponseRequest extends WebauthnLoginResponseRequest { response: { attestationObject: string; clientDataJson: string; diff --git a/apps/web/src/app/auth/core/services/webauthn/request/webauthn-response.request.ts b/apps/web/src/app/auth/core/services/webauthn-login/request/webauthn-login-response.request.ts similarity index 88% rename from apps/web/src/app/auth/core/services/webauthn/request/webauthn-response.request.ts rename to apps/web/src/app/auth/core/services/webauthn-login/request/webauthn-login-response.request.ts index e52cca70cb8..fd36d07c678 100644 --- a/apps/web/src/app/auth/core/services/webauthn/request/webauthn-response.request.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/request/webauthn-login-response.request.ts @@ -1,6 +1,6 @@ import { Utils } from "@bitwarden/common/platform/misc/utils"; -export abstract class WebauthnResponseRequest { +export abstract class WebauthnLoginResponseRequest { id: string; rawId: string; type: string; diff --git a/apps/web/src/app/auth/core/services/webauthn/response/credential-create-options.response.ts b/apps/web/src/app/auth/core/services/webauthn-login/response/webauthn-login-credential-create-options.response.ts similarity index 84% rename from apps/web/src/app/auth/core/services/webauthn/response/credential-create-options.response.ts rename to apps/web/src/app/auth/core/services/webauthn-login/response/webauthn-login-credential-create-options.response.ts index 5e258d14ae5..9c14ac139be 100644 --- a/apps/web/src/app/auth/core/services/webauthn/response/credential-create-options.response.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/response/webauthn-login-credential-create-options.response.ts @@ -1,7 +1,7 @@ import { ChallengeResponse } from "@bitwarden/common/auth/models/response/two-factor-web-authn.response"; import { BaseResponse } from "@bitwarden/common/models/response/base.response"; -export class CredentialCreateOptionsResponse extends BaseResponse { +export class WebauthnLoginCredentialCreateOptionsResponse extends BaseResponse { options: ChallengeResponse; token: string; diff --git a/apps/web/src/app/auth/core/services/webauthn/response/webauthn-credential.response.ts b/apps/web/src/app/auth/core/services/webauthn-login/response/webauthn-login-credential.response.ts similarity index 83% rename from apps/web/src/app/auth/core/services/webauthn/response/webauthn-credential.response.ts rename to apps/web/src/app/auth/core/services/webauthn-login/response/webauthn-login-credential.response.ts index 81f390096c3..c6746051b3f 100644 --- a/apps/web/src/app/auth/core/services/webauthn/response/webauthn-credential.response.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/response/webauthn-login-credential.response.ts @@ -1,6 +1,6 @@ import { BaseResponse } from "@bitwarden/common/models/response/base.response"; -export class WebauthnCredentialResponse extends BaseResponse { +export class WebauthnLoginCredentialResponse extends BaseResponse { id: string; name: string; prfSupport: boolean; diff --git a/apps/web/src/app/auth/core/services/webauthn/webauthn-api.service.ts b/apps/web/src/app/auth/core/services/webauthn-login/webauthn-login-api.service.ts similarity index 74% rename from apps/web/src/app/auth/core/services/webauthn/webauthn-api.service.ts rename to apps/web/src/app/auth/core/services/webauthn-login/webauthn-login-api.service.ts index d41ea33b692..33e1aea369b 100644 --- a/apps/web/src/app/auth/core/services/webauthn/webauthn-api.service.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/webauthn-login-api.service.ts @@ -6,11 +6,11 @@ import { ListResponse } from "@bitwarden/common/models/response/list.response"; import { Verification } from "@bitwarden/common/types/verification"; import { SaveCredentialRequest } from "./request/save-credential.request"; -import { CredentialCreateOptionsResponse } from "./response/credential-create-options.response"; -import { WebauthnCredentialResponse } from "./response/webauthn-credential.response"; +import { WebauthnLoginCredentialCreateOptionsResponse } from "./response/webauthn-login-credential-create-options.response"; +import { WebauthnLoginCredentialResponse } from "./response/webauthn-login-credential.response"; @Injectable() -export class WebauthnApiService { +export class WebauthnLoginApiService { constructor( private apiService: ApiService, private userVerificationService: UserVerificationService @@ -18,10 +18,10 @@ export class WebauthnApiService { async getCredentialCreateOptions( verification: Verification - ): Promise { + ): Promise { const request = await this.userVerificationService.buildRequest(verification); const response = await this.apiService.send("POST", "/webauthn/options", request, true, true); - return new CredentialCreateOptionsResponse(response); + return new WebauthnLoginCredentialCreateOptionsResponse(response); } async saveCredential(request: SaveCredentialRequest): Promise { @@ -29,7 +29,7 @@ export class WebauthnApiService { return true; } - getCredentials(): Promise> { + getCredentials(): Promise> { return this.apiService.send("GET", "/webauthn", null, true, true); } diff --git a/apps/web/src/app/auth/core/services/webauthn/webauthn.service.spec.ts b/apps/web/src/app/auth/core/services/webauthn-login/webauthn-login.service.spec.ts similarity index 83% rename from apps/web/src/app/auth/core/services/webauthn/webauthn.service.spec.ts rename to apps/web/src/app/auth/core/services/webauthn-login/webauthn-login.service.spec.ts index fbffbe28ff0..070513f19e8 100644 --- a/apps/web/src/app/auth/core/services/webauthn/webauthn.service.spec.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/webauthn-login.service.spec.ts @@ -2,21 +2,21 @@ import { mock, MockProxy } from "jest-mock-extended"; import { CredentialCreateOptionsView } from "../../views/credential-create-options.view"; -import { WebauthnApiService } from "./webauthn-api.service"; -import { WebauthnService } from "./webauthn.service"; +import { WebauthnLoginApiService } from "./webauthn-login-api.service"; +import { WebauthnLoginService } from "./webauthn-login.service"; describe("WebauthnService", () => { - let apiService!: MockProxy; + let apiService!: MockProxy; let credentials: MockProxy; - let webauthnService!: WebauthnService; + let webauthnService!: WebauthnLoginService; beforeAll(() => { // Polyfill missing class window.PublicKeyCredential = class {} as any; window.AuthenticatorAttestationResponse = class {} as any; - apiService = mock(); + apiService = mock(); credentials = mock(); - webauthnService = new WebauthnService(apiService, credentials); + webauthnService = new WebauthnLoginService(apiService, credentials); }); describe("createCredential", () => { diff --git a/apps/web/src/app/auth/core/services/webauthn/webauthn.service.ts b/apps/web/src/app/auth/core/services/webauthn-login/webauthn-login.service.ts similarity index 89% rename from apps/web/src/app/auth/core/services/webauthn/webauthn.service.ts rename to apps/web/src/app/auth/core/services/webauthn-login/webauthn-login.service.ts index 10e82b8acef..67ffaba056e 100644 --- a/apps/web/src/app/auth/core/services/webauthn/webauthn.service.ts +++ b/apps/web/src/app/auth/core/services/webauthn-login/webauthn-login.service.ts @@ -8,11 +8,11 @@ import { CredentialCreateOptionsView } from "../../views/credential-create-optio import { WebauthnCredentialView } from "../../views/webauth-credential.view"; import { SaveCredentialRequest } from "./request/save-credential.request"; -import { WebauthnAttestationResponseRequest } from "./request/webauthn-attestation-response.request"; -import { WebauthnApiService } from "./webauthn-api.service"; +import { WebauthnLoginAttestationResponseRequest } from "./request/webauthn-login-attestation-response.request"; +import { WebauthnLoginApiService } from "./webauthn-login-api.service"; @Injectable() -export class WebauthnService { +export class WebauthnLoginService { private navigatorCredentials: CredentialsContainer; private _refresh$ = new BehaviorSubject(undefined); private _loading$ = new BehaviorSubject(true); @@ -26,7 +26,7 @@ export class WebauthnService { readonly loading$ = this._loading$.asObservable(); constructor( - private apiService: WebauthnApiService, + private apiService: WebauthnLoginApiService, @Optional() navigatorCredentials?: CredentialsContainer, @Optional() private logService?: LogService ) { @@ -66,7 +66,7 @@ export class WebauthnService { name: string ) { const request = new SaveCredentialRequest(); - request.deviceResponse = new WebauthnAttestationResponseRequest(deviceResponse); + request.deviceResponse = new WebauthnLoginAttestationResponseRequest(deviceResponse); request.token = credentialOptions.token; request.name = name; await this.apiService.saveCredential(request); diff --git a/apps/web/src/app/auth/core/services/webauthn/index.ts b/apps/web/src/app/auth/core/services/webauthn/index.ts deleted file mode 100644 index d6d083a726e..00000000000 --- a/apps/web/src/app/auth/core/services/webauthn/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./webauthn.service"; diff --git a/apps/web/src/app/auth/core/services/webauthn/request/save-credential.request.ts b/apps/web/src/app/auth/core/services/webauthn/request/save-credential.request.ts deleted file mode 100644 index 94ba5bd56c6..00000000000 --- a/apps/web/src/app/auth/core/services/webauthn/request/save-credential.request.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { WebauthnResponseRequest } from "./webauthn-response.request"; - -export class SaveCredentialRequest { - deviceResponse: WebauthnResponseRequest; - name: string; - token: string; -} diff --git a/apps/web/src/app/auth/settings/webauthn-login-settings/create-credential-dialog/create-credential-dialog.component.ts b/apps/web/src/app/auth/settings/webauthn-login-settings/create-credential-dialog/create-credential-dialog.component.ts index 098b5392bb7..531515a949f 100644 --- a/apps/web/src/app/auth/settings/webauthn-login-settings/create-credential-dialog/create-credential-dialog.component.ts +++ b/apps/web/src/app/auth/settings/webauthn-login-settings/create-credential-dialog/create-credential-dialog.component.ts @@ -10,7 +10,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { DialogService } from "@bitwarden/components"; -import { WebauthnService } from "../../../core"; +import { WebauthnLoginService } from "../../../core"; import { CredentialCreateOptionsView } from "../../../core/views/credential-create-options.view"; import { CreatePasskeyFailedIcon } from "./create-passkey-failed.icon"; @@ -50,7 +50,7 @@ export class CreateCredentialDialogComponent implements OnInit { constructor( private formBuilder: FormBuilder, private dialogRef: DialogRef, - private webauthnService: WebauthnService, + private webauthnService: WebauthnLoginService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private logService: LogService diff --git a/apps/web/src/app/auth/settings/webauthn-login-settings/delete-credential-dialog/delete-credential-dialog.component.ts b/apps/web/src/app/auth/settings/webauthn-login-settings/delete-credential-dialog/delete-credential-dialog.component.ts index 9baa7e90013..7cb03238392 100644 --- a/apps/web/src/app/auth/settings/webauthn-login-settings/delete-credential-dialog/delete-credential-dialog.component.ts +++ b/apps/web/src/app/auth/settings/webauthn-login-settings/delete-credential-dialog/delete-credential-dialog.component.ts @@ -10,7 +10,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service" import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { DialogService } from "@bitwarden/components"; -import { WebauthnService } from "../../../core"; +import { WebauthnLoginService } from "../../../core"; import { WebauthnCredentialView } from "../../../core/views/webauth-credential.view"; export interface DeleteCredentialDialogParams { @@ -32,7 +32,7 @@ export class DeleteCredentialDialogComponent implements OnInit, OnDestroy { @Inject(DIALOG_DATA) private params: DeleteCredentialDialogParams, private formBuilder: FormBuilder, private dialogRef: DialogRef, - private webauthnService: WebauthnService, + private webauthnService: WebauthnLoginService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private logService: LogService diff --git a/apps/web/src/app/auth/settings/webauthn-login-settings/webauthn-login-settings.component.ts b/apps/web/src/app/auth/settings/webauthn-login-settings/webauthn-login-settings.component.ts index 73780a2a7a1..3c59bd30ed4 100644 --- a/apps/web/src/app/auth/settings/webauthn-login-settings/webauthn-login-settings.component.ts +++ b/apps/web/src/app/auth/settings/webauthn-login-settings/webauthn-login-settings.component.ts @@ -3,7 +3,7 @@ import { Subject, takeUntil } from "rxjs"; import { DialogService } from "@bitwarden/components"; -import { WebauthnService } from "../../core"; +import { WebauthnLoginService } from "../../core"; import { WebauthnCredentialView } from "../../core/views/webauth-credential.view"; import { openCreateCredentialDialog } from "./create-credential-dialog/create-credential-dialog.component"; @@ -24,7 +24,10 @@ export class WebauthnLoginSettingsComponent implements OnInit, OnDestroy { protected credentials?: WebauthnCredentialView[]; protected loading = true; - constructor(private webauthnService: WebauthnService, private dialogService: DialogService) {} + constructor( + private webauthnService: WebauthnLoginService, + private dialogService: DialogService + ) {} @HostBinding("attr.aria-busy") get ariaBusy() {