setup launchSsoBrowserWindow() for Desktop

This commit is contained in:
rr-bw 2024-09-14 12:59:51 -07:00
parent da18b42f80
commit d88606a6fd
No known key found for this signature in database
GPG Key ID: 3FA13C3ADEE51D5D
7 changed files with 44 additions and 23 deletions

View File

@ -573,11 +573,11 @@ const safeProviders: SafeProvider[] = [
provide: LoginService,
useClass: ExtensionLoginService,
deps: [
SsoLoginServiceAbstraction,
PasswordGenerationServiceAbstraction,
CryptoFunctionServiceAbstraction,
EnvironmentService,
PasswordGenerationServiceAbstraction,
PlatformUtilsServiceAbstraction,
SsoLoginServiceAbstraction,
],
}),
];

View File

@ -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({

View File

@ -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<void | null> {
override async launchSsoBrowserWindow(email: string, clientId: "desktop"): Promise<void | null> {
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"),

View File

@ -222,11 +222,11 @@ const safeProviders: SafeProvider[] = [
provide: LoginService,
useClass: WebLoginService,
deps: [
SsoLoginServiceAbstraction,
PasswordGenerationServiceAbstraction,
CryptoFunctionServiceAbstraction,
EnvironmentService,
PasswordGenerationServiceAbstraction,
PlatformUtilsServiceAbstraction,
SsoLoginServiceAbstraction,
],
}),
];

View File

@ -1314,11 +1314,11 @@ const safeProviders: SafeProvider[] = [
provide: LoginService,
useClass: DefaultLoginService,
deps: [
SsoLoginServiceAbstraction,
PasswordGenerationServiceAbstraction,
CryptoFunctionServiceAbstraction,
EnvironmentService,
PasswordGenerationServiceAbstraction,
PlatformUtilsServiceAbstraction,
SsoLoginServiceAbstraction,
],
}),
];

View File

@ -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

View File

@ -251,8 +251,14 @@
{{ "logInWithPasskey" | i18n }}
</button>
<!-- Link to SSO page -->
<button type="button" bitButton block buttonType="secondary" routerLink="/sso">
<!-- Button to Login with SSO -->
<button
type="button"
bitButton
block
buttonType="secondary"
(click)="launchSsoBrowserWindow('desktop')"
>
<i class="bwi bwi-provider tw-mr-1"></i>
{{ "useSingleSignOn" | i18n }}
</button>