import { Component } from '@angular/core'; import { ConstantsService } from 'jslib/services/constants.service' import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { Utils } from 'jslib/misc/utils'; @Component({ selector: 'app-home', templateUrl: 'home.component.html', }) export class HomeComponent { constructor( protected platformUtilsService: PlatformUtilsService, private passwordGenerationService : PasswordGenerationService, private cryptoFunctionService: CryptoFunctionService, private environmentService: EnvironmentService, private storageService : StorageService) { } async launchSsoBrowser() { // Generate necessary sso params const passwordOptions: any = { type: 'password', length: 64, uppercase: true, lowercase: true, numbers: true, special: false, }; const state = await this.passwordGenerationService.generatePassword(passwordOptions); let codeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions); const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, 'sha256'); const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash); await this.storageService.save(ConstantsService.ssoCodeVerifierKey, codeVerifier); await this.storageService.save(ConstantsService.ssoStateKey, state); await this.storageService.save(ConstantsService.ssoClientId, ConstantsService.webClientId); let url = this.environmentService.getWebVaultUrl(); if (url == null) { url = 'https://vault.bitwarden.com'; } const ssoRedirectUri = url + '/sso-connector.html'; // Launch browser this.platformUtilsService.launchUri(url + '/#/sso?clientId=' + ConstantsService.webClientId + '&redirectUri=' + encodeURIComponent(ssoRedirectUri) + '&state=' + state + '&codeChallenge=' + codeChallenge); } }