diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 260bd23a367..ab883768bb5 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -573,11 +573,11 @@ const safeProviders: SafeProvider[] = [ provide: LoginService, useClass: ExtensionLoginService, deps: [ - SsoLoginServiceAbstraction, - PasswordGenerationServiceAbstraction, CryptoFunctionServiceAbstraction, EnvironmentService, + PasswordGenerationServiceAbstraction, PlatformUtilsServiceAbstraction, + SsoLoginServiceAbstraction, ], }), ]; diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index d4b51ca1c7e..d29633d3e0d 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -19,7 +19,7 @@ import { CLIENT_TYPE, } from "@bitwarden/angular/services/injection-tokens"; import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; -import { SetPasswordJitService } from "@bitwarden/auth/angular"; +import { LoginService, SetPasswordJitService } from "@bitwarden/auth/angular"; import { InternalUserDecryptionOptionsServiceAbstraction, PinServiceAbstraction, @@ -35,6 +35,7 @@ import { KdfConfigService as KdfConfigServiceAbstraction, } from "@bitwarden/common/auth/abstractions/kdf-config.service"; import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction"; +import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction"; import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service"; import { ClientType } from "@bitwarden/common/enums"; import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto-function.service"; @@ -43,6 +44,7 @@ import { CryptoService as CryptoServiceAbstraction, } from "@bitwarden/common/platform/abstractions/crypto.service"; import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service"; +import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service"; import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service"; @@ -71,6 +73,7 @@ import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/vau import { DialogService } from "@bitwarden/components"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; +import { DesktopLoginService } from "../../auth/login/desktop-login.service"; import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service"; import { DesktopSettingsService } from "../../platform/services/desktop-settings.service"; import { ElectronBiometricsService } from "../../platform/services/electron-biometrics.service"; @@ -289,6 +292,17 @@ const safeProviders: SafeProvider[] = [ InternalUserDecryptionOptionsServiceAbstraction, ], }), + safeProvider({ + provide: LoginService, + useClass: DesktopLoginService, + deps: [ + CryptoFunctionServiceAbstraction, + EnvironmentService, + PasswordGenerationServiceAbstraction, + PlatformUtilsServiceAbstraction, + SsoLoginServiceAbstraction, + ], + }), ]; @NgModule({ diff --git a/apps/desktop/src/auth/login/desktop-login.service.ts b/apps/desktop/src/auth/login/desktop-login.service.ts index aec0f13e4b3..a8c640b5269 100644 --- a/apps/desktop/src/auth/login/desktop-login.service.ts +++ b/apps/desktop/src/auth/login/desktop-login.service.ts @@ -4,24 +4,23 @@ import { DefaultLoginService, LoginService } from "@bitwarden/auth/angular"; import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction"; import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; +import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; export class DesktopLoginService extends DefaultLoginService implements LoginService { - ssoLoginService = inject(SsoLoginServiceAbstraction); - passwordGenerationService = inject(PasswordGenerationServiceAbstraction); cryptoFunctionService = inject(CryptoFunctionService); environmentService = inject(EnvironmentService); + i18nService = inject(I18nService); + // TODO-rr-bw: refactor to not use deprecated service + passwordGenerationService = inject(PasswordGenerationServiceAbstraction); platformUtilsService = inject(PlatformUtilsService); + ssoLoginService = inject(SsoLoginServiceAbstraction); - async launchSsoBrowserWindow( - email: string, - clientId: string, - redirectUri: string, - ): Promise { + override async launchSsoBrowserWindow(email: string, clientId: "desktop"): Promise { if (!ipc.platform.isAppImage && !ipc.platform.isSnapStore && !ipc.platform.isDev) { - return super.launchSsoBrowser(clientId, redirectUri); + return super.launchSsoBrowserWindow(email, clientId); } // Save email for SSO @@ -36,18 +35,20 @@ export class DesktopLoginService extends DefaultLoginService implements LoginSer numbers: true, special: false, }; + const state = await this.passwordGenerationService.generatePassword(passwordOptions); - const ssoCodeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions); - const codeVerifierHash = await this.cryptoFunctionService.hash(ssoCodeVerifier, "sha256"); + const codeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions); + const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, "sha256"); const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash); // Save SSO params await this.ssoLoginService.setSsoState(state); - await this.ssoLoginService.setCodeVerifier(ssoCodeVerifier); + await this.ssoLoginService.setCodeVerifier(codeVerifier); try { await ipc.platform.localhostCallbackService.openSsoPrompt(codeChallenge, state); } catch (err) { + // TODO-rr-bw: refactor to not use deprecated service this.platformUtilsService.showToast( "error", this.i18nService.t("errorOccured"), diff --git a/apps/web/src/app/core/core.module.ts b/apps/web/src/app/core/core.module.ts index 2a7d654b53a..bdc0294b61b 100644 --- a/apps/web/src/app/core/core.module.ts +++ b/apps/web/src/app/core/core.module.ts @@ -222,11 +222,11 @@ const safeProviders: SafeProvider[] = [ provide: LoginService, useClass: WebLoginService, deps: [ - SsoLoginServiceAbstraction, - PasswordGenerationServiceAbstraction, CryptoFunctionServiceAbstraction, EnvironmentService, + PasswordGenerationServiceAbstraction, PlatformUtilsServiceAbstraction, + SsoLoginServiceAbstraction, ], }), ]; diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 71a2ef9cb0f..185414935ed 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -1314,11 +1314,11 @@ const safeProviders: SafeProvider[] = [ provide: LoginService, useClass: DefaultLoginService, deps: [ - SsoLoginServiceAbstraction, - PasswordGenerationServiceAbstraction, CryptoFunctionServiceAbstraction, EnvironmentService, + PasswordGenerationServiceAbstraction, PlatformUtilsServiceAbstraction, + SsoLoginServiceAbstraction, ], }), ]; diff --git a/libs/auth/src/angular/login/default-login.service.ts b/libs/auth/src/angular/login/default-login.service.ts index b6ec1e8d54e..87dbc39cd9d 100644 --- a/libs/auth/src/angular/login/default-login.service.ts +++ b/libs/auth/src/angular/login/default-login.service.ts @@ -11,12 +11,12 @@ import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legac export class DefaultLoginService implements LoginService { constructor( - protected ssoLoginService: SsoLoginServiceAbstraction, - // TODO-rr-bw: refactor to not use deprecated service - protected passwordGenerationService: PasswordGenerationServiceAbstraction, protected cryptoFunctionService: CryptoFunctionService, protected environmentService: EnvironmentService, + // TODO-rr-bw: refactor to not use deprecated service + protected passwordGenerationService: PasswordGenerationServiceAbstraction, protected platformUtilsService: PlatformUtilsService, + protected ssoLoginService: SsoLoginServiceAbstraction, ) {} // Web diff --git a/libs/auth/src/angular/login/login.component.html b/libs/auth/src/angular/login/login.component.html index be81cf8e867..8ff0ba1fad5 100644 --- a/libs/auth/src/angular/login/login.component.html +++ b/libs/auth/src/angular/login/login.component.html @@ -251,8 +251,14 @@ {{ "logInWithPasskey" | i18n }} - -