setup launchSsoBrowserWindow() for Desktop
This commit is contained in:
parent
da18b42f80
commit
d88606a6fd
|
@ -573,11 +573,11 @@ const safeProviders: SafeProvider[] = [
|
||||||
provide: LoginService,
|
provide: LoginService,
|
||||||
useClass: ExtensionLoginService,
|
useClass: ExtensionLoginService,
|
||||||
deps: [
|
deps: [
|
||||||
SsoLoginServiceAbstraction,
|
|
||||||
PasswordGenerationServiceAbstraction,
|
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
EnvironmentService,
|
EnvironmentService,
|
||||||
|
PasswordGenerationServiceAbstraction,
|
||||||
PlatformUtilsServiceAbstraction,
|
PlatformUtilsServiceAbstraction,
|
||||||
|
SsoLoginServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
CLIENT_TYPE,
|
CLIENT_TYPE,
|
||||||
} from "@bitwarden/angular/services/injection-tokens";
|
} from "@bitwarden/angular/services/injection-tokens";
|
||||||
import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module";
|
import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module";
|
||||||
import { SetPasswordJitService } from "@bitwarden/auth/angular";
|
import { LoginService, SetPasswordJitService } from "@bitwarden/auth/angular";
|
||||||
import {
|
import {
|
||||||
InternalUserDecryptionOptionsServiceAbstraction,
|
InternalUserDecryptionOptionsServiceAbstraction,
|
||||||
PinServiceAbstraction,
|
PinServiceAbstraction,
|
||||||
|
@ -35,6 +35,7 @@ import {
|
||||||
KdfConfigService as KdfConfigServiceAbstraction,
|
KdfConfigService as KdfConfigServiceAbstraction,
|
||||||
} from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
} from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
||||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction";
|
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 { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
|
||||||
import { ClientType } from "@bitwarden/common/enums";
|
import { ClientType } from "@bitwarden/common/enums";
|
||||||
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
|
@ -43,6 +44,7 @@ import {
|
||||||
CryptoService as CryptoServiceAbstraction,
|
CryptoService as CryptoServiceAbstraction,
|
||||||
} from "@bitwarden/common/platform/abstractions/crypto.service";
|
} from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.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 { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.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 { DialogService } from "@bitwarden/components";
|
||||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
|
import { DesktopLoginService } from "../../auth/login/desktop-login.service";
|
||||||
import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service";
|
import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service";
|
||||||
import { DesktopSettingsService } from "../../platform/services/desktop-settings.service";
|
import { DesktopSettingsService } from "../../platform/services/desktop-settings.service";
|
||||||
import { ElectronBiometricsService } from "../../platform/services/electron-biometrics.service";
|
import { ElectronBiometricsService } from "../../platform/services/electron-biometrics.service";
|
||||||
|
@ -289,6 +292,17 @@ const safeProviders: SafeProvider[] = [
|
||||||
InternalUserDecryptionOptionsServiceAbstraction,
|
InternalUserDecryptionOptionsServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
safeProvider({
|
||||||
|
provide: LoginService,
|
||||||
|
useClass: DesktopLoginService,
|
||||||
|
deps: [
|
||||||
|
CryptoFunctionServiceAbstraction,
|
||||||
|
EnvironmentService,
|
||||||
|
PasswordGenerationServiceAbstraction,
|
||||||
|
PlatformUtilsServiceAbstraction,
|
||||||
|
SsoLoginServiceAbstraction,
|
||||||
|
],
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -4,24 +4,23 @@ import { DefaultLoginService, LoginService } from "@bitwarden/auth/angular";
|
||||||
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.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 { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
|
||||||
|
|
||||||
export class DesktopLoginService extends DefaultLoginService implements LoginService {
|
export class DesktopLoginService extends DefaultLoginService implements LoginService {
|
||||||
ssoLoginService = inject(SsoLoginServiceAbstraction);
|
|
||||||
passwordGenerationService = inject(PasswordGenerationServiceAbstraction);
|
|
||||||
cryptoFunctionService = inject(CryptoFunctionService);
|
cryptoFunctionService = inject(CryptoFunctionService);
|
||||||
environmentService = inject(EnvironmentService);
|
environmentService = inject(EnvironmentService);
|
||||||
|
i18nService = inject(I18nService);
|
||||||
|
// TODO-rr-bw: refactor to not use deprecated service
|
||||||
|
passwordGenerationService = inject(PasswordGenerationServiceAbstraction);
|
||||||
platformUtilsService = inject(PlatformUtilsService);
|
platformUtilsService = inject(PlatformUtilsService);
|
||||||
|
ssoLoginService = inject(SsoLoginServiceAbstraction);
|
||||||
|
|
||||||
async launchSsoBrowserWindow(
|
override async launchSsoBrowserWindow(email: string, clientId: "desktop"): Promise<void | null> {
|
||||||
email: string,
|
|
||||||
clientId: string,
|
|
||||||
redirectUri: string,
|
|
||||||
): Promise<void | null> {
|
|
||||||
if (!ipc.platform.isAppImage && !ipc.platform.isSnapStore && !ipc.platform.isDev) {
|
if (!ipc.platform.isAppImage && !ipc.platform.isSnapStore && !ipc.platform.isDev) {
|
||||||
return super.launchSsoBrowser(clientId, redirectUri);
|
return super.launchSsoBrowserWindow(email, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save email for SSO
|
// Save email for SSO
|
||||||
|
@ -36,18 +35,20 @@ export class DesktopLoginService extends DefaultLoginService implements LoginSer
|
||||||
numbers: true,
|
numbers: true,
|
||||||
special: false,
|
special: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const state = await this.passwordGenerationService.generatePassword(passwordOptions);
|
const state = await this.passwordGenerationService.generatePassword(passwordOptions);
|
||||||
const ssoCodeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions);
|
const codeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions);
|
||||||
const codeVerifierHash = await this.cryptoFunctionService.hash(ssoCodeVerifier, "sha256");
|
const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, "sha256");
|
||||||
const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash);
|
const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash);
|
||||||
|
|
||||||
// Save SSO params
|
// Save SSO params
|
||||||
await this.ssoLoginService.setSsoState(state);
|
await this.ssoLoginService.setSsoState(state);
|
||||||
await this.ssoLoginService.setCodeVerifier(ssoCodeVerifier);
|
await this.ssoLoginService.setCodeVerifier(codeVerifier);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ipc.platform.localhostCallbackService.openSsoPrompt(codeChallenge, state);
|
await ipc.platform.localhostCallbackService.openSsoPrompt(codeChallenge, state);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// TODO-rr-bw: refactor to not use deprecated service
|
||||||
this.platformUtilsService.showToast(
|
this.platformUtilsService.showToast(
|
||||||
"error",
|
"error",
|
||||||
this.i18nService.t("errorOccured"),
|
this.i18nService.t("errorOccured"),
|
||||||
|
|
|
@ -222,11 +222,11 @@ const safeProviders: SafeProvider[] = [
|
||||||
provide: LoginService,
|
provide: LoginService,
|
||||||
useClass: WebLoginService,
|
useClass: WebLoginService,
|
||||||
deps: [
|
deps: [
|
||||||
SsoLoginServiceAbstraction,
|
|
||||||
PasswordGenerationServiceAbstraction,
|
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
EnvironmentService,
|
EnvironmentService,
|
||||||
|
PasswordGenerationServiceAbstraction,
|
||||||
PlatformUtilsServiceAbstraction,
|
PlatformUtilsServiceAbstraction,
|
||||||
|
SsoLoginServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -1314,11 +1314,11 @@ const safeProviders: SafeProvider[] = [
|
||||||
provide: LoginService,
|
provide: LoginService,
|
||||||
useClass: DefaultLoginService,
|
useClass: DefaultLoginService,
|
||||||
deps: [
|
deps: [
|
||||||
SsoLoginServiceAbstraction,
|
|
||||||
PasswordGenerationServiceAbstraction,
|
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
EnvironmentService,
|
EnvironmentService,
|
||||||
|
PasswordGenerationServiceAbstraction,
|
||||||
PlatformUtilsServiceAbstraction,
|
PlatformUtilsServiceAbstraction,
|
||||||
|
SsoLoginServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -11,12 +11,12 @@ import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legac
|
||||||
|
|
||||||
export class DefaultLoginService implements LoginService {
|
export class DefaultLoginService implements LoginService {
|
||||||
constructor(
|
constructor(
|
||||||
protected ssoLoginService: SsoLoginServiceAbstraction,
|
|
||||||
// TODO-rr-bw: refactor to not use deprecated service
|
|
||||||
protected passwordGenerationService: PasswordGenerationServiceAbstraction,
|
|
||||||
protected cryptoFunctionService: CryptoFunctionService,
|
protected cryptoFunctionService: CryptoFunctionService,
|
||||||
protected environmentService: EnvironmentService,
|
protected environmentService: EnvironmentService,
|
||||||
|
// TODO-rr-bw: refactor to not use deprecated service
|
||||||
|
protected passwordGenerationService: PasswordGenerationServiceAbstraction,
|
||||||
protected platformUtilsService: PlatformUtilsService,
|
protected platformUtilsService: PlatformUtilsService,
|
||||||
|
protected ssoLoginService: SsoLoginServiceAbstraction,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// Web
|
// Web
|
||||||
|
|
|
@ -251,8 +251,14 @@
|
||||||
{{ "logInWithPasskey" | i18n }}
|
{{ "logInWithPasskey" | i18n }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Link to SSO page -->
|
<!-- Button to Login with SSO -->
|
||||||
<button type="button" bitButton block buttonType="secondary" routerLink="/sso">
|
<button
|
||||||
|
type="button"
|
||||||
|
bitButton
|
||||||
|
block
|
||||||
|
buttonType="secondary"
|
||||||
|
(click)="launchSsoBrowserWindow('desktop')"
|
||||||
|
>
|
||||||
<i class="bwi bwi-provider tw-mr-1"></i>
|
<i class="bwi bwi-provider tw-mr-1"></i>
|
||||||
{{ "useSingleSignOn" | i18n }}
|
{{ "useSingleSignOn" | i18n }}
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in New Issue