2018-04-04 20:19:44 +02:00
|
|
|
import { Component } from "@angular/core";
|
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { CryptoFunctionService } from "jslib-common/abstractions/cryptoFunction.service";
|
|
|
|
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
|
|
|
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
2022-01-27 22:22:51 +01:00
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
2020-08-11 22:25:07 +02:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { Utils } from "jslib-common/misc/utils";
|
2020-08-11 22:25:07 +02:00
|
|
|
|
2018-04-04 20:19:44 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-home",
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: "home.component.html",
|
2018-04-04 20:19:44 +02:00
|
|
|
})
|
2020-08-24 16:17:15 +02:00
|
|
|
export class HomeComponent {
|
|
|
|
constructor(
|
|
|
|
protected platformUtilsService: PlatformUtilsService,
|
|
|
|
private passwordGenerationService: PasswordGenerationService,
|
2022-01-27 22:22:51 +01:00
|
|
|
private stateService: StateService,
|
2020-08-24 16:17:15 +02:00
|
|
|
private cryptoFunctionService: CryptoFunctionService,
|
|
|
|
private environmentService: EnvironmentService
|
|
|
|
) {}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-08-24 16:17:15 +02:00
|
|
|
async launchSsoBrowser() {
|
|
|
|
// Generate necessary sso params
|
|
|
|
const passwordOptions: any = {
|
|
|
|
type: "password",
|
|
|
|
length: 64,
|
|
|
|
uppercase: true,
|
|
|
|
lowercase: true,
|
|
|
|
numbers: true,
|
|
|
|
special: false,
|
|
|
|
};
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-08-24 16:17:15 +02:00
|
|
|
const state =
|
|
|
|
(await this.passwordGenerationService.generatePassword(passwordOptions)) +
|
|
|
|
":clientId=browser";
|
|
|
|
const codeVerifier = await this.passwordGenerationService.generatePassword(passwordOptions);
|
|
|
|
const codeVerifierHash = await this.cryptoFunctionService.hash(codeVerifier, "sha256");
|
|
|
|
const codeChallenge = Utils.fromBufferToUrlB64(codeVerifierHash);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
await this.stateService.setSsoCodeVerifier(codeVerifier);
|
|
|
|
await this.stateService.setSsoState(state);
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-08-24 16:17:15 +02:00
|
|
|
let url = this.environmentService.getWebVaultUrl();
|
|
|
|
if (url == null) {
|
|
|
|
url = "https://vault.bitwarden.com";
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-08-24 16:17:15 +02:00
|
|
|
const redirectUri = url + "/sso-connector.html";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-08-24 16:17:15 +02:00
|
|
|
// Launch browser
|
|
|
|
this.platformUtilsService.launchUri(
|
2021-12-21 15:43:35 +01:00
|
|
|
url +
|
2020-08-24 16:17:15 +02:00
|
|
|
"/#/sso?clientId=browser" +
|
|
|
|
"&redirectUri=" +
|
|
|
|
encodeURIComponent(redirectUri) +
|
2021-12-21 15:43:35 +01:00
|
|
|
"&state=" +
|
|
|
|
state +
|
2020-08-24 16:17:15 +02:00
|
|
|
"&codeChallenge=" +
|
|
|
|
codeChallenge
|
2021-12-21 15:43:35 +01:00
|
|
|
);
|
|
|
|
}
|
2020-08-11 22:25:07 +02:00
|
|
|
}
|