1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-29 12:55:21 +01:00

Cleaned up home.component.ts for feedback.

This commit is contained in:
Matt Smith 2020-08-12 14:17:55 -05:00
parent e10e006b51
commit 09b7d7ec16

View File

@ -1,9 +1,11 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ConstantsService } from 'jslib/services/constants.service'
import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service'; import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { PlatformUtilsService } from '../../../jslib/src/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { Utils } from 'jslib/misc/utils'; import { Utils } from 'jslib/misc/utils';
@ -13,8 +15,11 @@ import { Utils } from 'jslib/misc/utils';
}) })
export class HomeComponent { export class HomeComponent {
constructor( constructor(
protected platformUtilsService: PlatformUtilsService, private passwordGenerationService : PasswordGenerationService, protected platformUtilsService: PlatformUtilsService,
private cryptoFunctionService: CryptoFunctionService, private environmentService: EnvironmentService) { } private passwordGenerationService : PasswordGenerationService,
private cryptoFunctionService: CryptoFunctionService,
private environmentService: EnvironmentService,
private storageService : StorageService) { }
async launchSsoBrowser() { async launchSsoBrowser() {
// Generate necessary sso params // Generate necessary sso params
@ -28,18 +33,24 @@ export class HomeComponent {
}; };
const state = await this.passwordGenerationService.generatePassword(passwordOptions); const state = await this.passwordGenerationService.generatePassword(passwordOptions);
let ssoCodeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions); let 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);
const webUrl = 'https://localhost:8080'; await this.storageService.save(ConstantsService.ssoCodeVerifierKey, codeVerifier);
const clientId = 'browser'; await this.storageService.save(ConstantsService.ssoStateKey, state);
const ssoRedirectUri = 'https://localhost:8080/sso-connector.html'; 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 // Launch browser
this.platformUtilsService.launchUri(webUrl + '/#/sso?clientId=' + clientId + this.platformUtilsService.launchUri(url + '/#/sso?clientId=' + ConstantsService.webClientId +
'&redirectUri=' + encodeURIComponent(ssoRedirectUri) + '&redirectUri=' + encodeURIComponent(ssoRedirectUri) +
'&state=' + state + '&codeChallenge=' + codeChallenge + '&state=' + state + '&codeChallenge=' + codeChallenge);
'&codeVerifier=' + ssoCodeVerifier);
} }
} }