1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00

Add helper methods to EnvironmentService for retrieving urls (#435)

This commit is contained in:
Oscar Hinton
2021-07-23 20:03:52 +02:00
committed by GitHub
parent c77441b353
commit de288913e4
19 changed files with 234 additions and 158 deletions

View File

@@ -18,10 +18,7 @@ export abstract class CaptchaProtectedComponent {
protected platformUtilsService: PlatformUtilsService) { }
async setupCaptcha() {
let webVaultUrl = this.environmentService.getWebVaultUrl();
if (webVaultUrl == null) {
webVaultUrl = 'https://vault.bitwarden.com';
}
const webVaultUrl = this.environmentService.getWebVaultUrl();
this.captcha = new CaptchaIFrame(window, webVaultUrl,
this.i18nService, (token: string) => {

View File

@@ -6,6 +6,7 @@ import {
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { NotificationsService } from 'jslib-common/abstractions/notifications.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
@Directive()
@@ -23,13 +24,16 @@ export class EnvironmentComponent {
constructor(protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService,
protected i18nService: I18nService) {
this.baseUrl = environmentService.baseUrl || '';
this.webVaultUrl = environmentService.webVaultUrl || '';
this.apiUrl = environmentService.apiUrl || '';
this.identityUrl = environmentService.identityUrl || '';
this.iconsUrl = environmentService.iconsUrl || '';
this.notificationsUrl = environmentService.notificationsUrl || '';
this.enterpriseUrl = environmentService.enterpriseUrl || '';
const urls = this.environmentService.getUrls();
this.baseUrl = urls.base || '';
this.webVaultUrl = urls.webVault || '';
this.apiUrl = urls.api || '';
this.identityUrl = urls.identity || '';
this.iconsUrl = urls.icons || '';
this.notificationsUrl = urls.notifications || '';
this.enterpriseUrl = urls.enterprise || '';
}
async submit() {

View File

@@ -38,14 +38,7 @@ export class IconComponent implements OnChanges {
private iconsUrl: string;
constructor(environmentService: EnvironmentService, protected stateService: StateService) {
this.iconsUrl = environmentService.iconsUrl;
if (!this.iconsUrl) {
if (environmentService.baseUrl) {
this.iconsUrl = environmentService.baseUrl + '/icons';
} else {
this.iconsUrl = 'https://icons.bitwarden.net';
}
}
this.iconsUrl = environmentService.getIconsUrl();
}
async ngOnChanges() {

View File

@@ -57,10 +57,9 @@ export class LockComponent implements OnInit {
(await this.cryptoService.hasKeyStored('biometric') || !this.platformUtilsService.supportsSecureStorage());
this.biometricText = await this.storageService.get(ConstantsService.biometricText);
this.email = await this.userService.getEmail();
let vaultUrl = this.environmentService.getWebVaultUrl();
if (vaultUrl == null) {
vaultUrl = 'https://bitwarden.com';
}
const webVaultUrl = this.environmentService.getWebVaultUrl();
const vaultUrl = webVaultUrl === 'https://vault.bitwarden.com' ? 'https://bitwarden.com' : webVaultUrl;
this.webVaultHostname = Utils.getHostname(vaultUrl);
}

View File

@@ -143,8 +143,7 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
await this.storageService.save(ConstantsService.ssoCodeVerifierKey, ssoCodeVerifier);
// Build URI
const webUrl = this.environmentService.getWebVaultUrl() == null ? 'https://vault.bitwarden.com' :
this.environmentService.getWebVaultUrl();
const webUrl = this.environmentService.getWebVaultUrl();
// Launch browser
this.platformUtilsService.launchUri(webUrl + '/#/sso?clientId=' + clientId +

View File

@@ -63,12 +63,7 @@ export class AddEditComponent implements OnInit {
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
];
const webVaultUrl = this.environmentService.getWebVaultUrl();
if (webVaultUrl == null) {
this.sendLinkBaseUrl = 'https://send.bitwarden.com/#';
} else {
this.sendLinkBaseUrl = webVaultUrl + '/#/send/';
}
this.sendLinkBaseUrl = this.environmentService.getSendUrl();
}
get link(): string {

View File

@@ -170,11 +170,7 @@ export class SendComponent implements OnInit {
}
copy(s: SendView) {
let sendLinkBaseUrl = 'https://send.bitwarden.com/#';
const webVaultUrl = this.environmentService.getWebVaultUrl();
if (webVaultUrl != null) {
sendLinkBaseUrl = webVaultUrl + '/#/send/';
}
const sendLinkBaseUrl = this.environmentService.getSendUrl();
const link = sendLinkBaseUrl + s.accessId + '/' + s.urlB64Key;
this.platformUtilsService.copyToClipboard(link);
this.platformUtilsService.showToast('success', null,

View File

@@ -7,6 +7,7 @@ import {
import { ApiService } from 'jslib-common/abstractions/api.service';
import { AuthService } from 'jslib-common/abstractions/auth.service';
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
@@ -43,7 +44,7 @@ export class SsoComponent {
protected i18nService: I18nService, protected route: ActivatedRoute,
protected storageService: StorageService, protected stateService: StateService,
protected platformUtilsService: PlatformUtilsService, protected apiService: ApiService,
protected cryptoFunctionService: CryptoFunctionService,
protected cryptoFunctionService: CryptoFunctionService, protected environmentService: EnvironmentService,
protected passwordGenerationService: PasswordGenerationService) { }
async ngOnInit() {
@@ -119,7 +120,7 @@ export class SsoComponent {
// Save state (regardless of new or existing)
await this.storageService.save(ConstantsService.ssoStateKey, state);
let authorizeUrl = this.apiService.identityBaseUrl + '/connect/authorize?' +
let authorizeUrl = this.environmentService.getIdentityUrl() + '/connect/authorize?' +
'client_id=' + this.clientId + '&redirect_uri=' + encodeURIComponent(this.redirectUri) + '&' +
'response_type=code&scope=api offline_access&' +
'state=' + state + '&code_challenge=' + codeChallenge + '&' +

View File

@@ -76,10 +76,7 @@ export class TwoFactorComponent implements OnInit, OnDestroy {
}
if (this.win != null && this.webAuthnSupported) {
let webVaultUrl = this.environmentService.getWebVaultUrl();
if (webVaultUrl == null) {
webVaultUrl = 'https://vault.bitwarden.com';
}
const webVaultUrl = this.environmentService.getWebVaultUrl();
this.webAuthn = new WebAuthnIFrame(this.win, webVaultUrl, this.webAuthnNewTab, this.platformUtilsService,
this.i18nService, (token: string) => {
this.token = token;