1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

Modifications made to support browser sso

This commit is contained in:
Matt Smith
2020-08-14 12:48:50 -05:00
parent 09b7d7ec16
commit 2d56510f0e
10 changed files with 99 additions and 42 deletions

View File

@@ -78,6 +78,7 @@ import BrowserMessagingService from '../services/browserMessaging.service';
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
import BrowserStorageService from '../services/browserStorage.service';
import I18nService from '../services/i18n.service';
import { PopupUtilsService } from '../popup/services/popup-utils.service';
import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service';
@@ -114,6 +115,7 @@ export default class MainBackground {
eventService: EventServiceAbstraction;
policyService: PolicyServiceAbstraction;
analytics: Analytics;
popupUtilsService: PopupUtilsService;
onUpdatedRan: boolean;
onReplacedRan: boolean;
@@ -200,6 +202,7 @@ export default class MainBackground {
this.notificationsService);
this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService,
this.storageService, this.appIdService);
this.popupUtilsService = new PopupUtilsService(this.platformUtilsService);
this.systemService = new SystemService(this.storageService, this.vaultTimeoutService,
this.messagingService, this.platformUtilsService, () => {
const forceWindowReload = this.platformUtilsService.isSafari() ||
@@ -217,7 +220,7 @@ export default class MainBackground {
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService,
this.platformUtilsService as BrowserPlatformUtilsService, this.storageService, this.i18nService,
this.analytics, this.notificationsService, this.systemService, this.vaultTimeoutService, this.syncService,
this.authService, this.stateService, this.environmentService);
this.authService, this.stateService, this.environmentService, this.popupUtilsService);
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService,
this.platformUtilsService, this.analytics, this.vaultTimeoutService);

View File

@@ -13,6 +13,7 @@ import { ConstantsService } from 'jslib/services/constants.service';
import { EnvironmentService } from 'jslib/abstractions/environment.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { NotificationsService } from 'jslib/abstractions/notifications.service';
import { PopupUtilsService } from '../popup/services/popup-utils.service';
import { StateService } from 'jslib/abstractions/state.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { SyncService } from 'jslib/abstractions/sync.service';
@@ -33,19 +34,13 @@ export default class RuntimeBackground {
private isSafari: boolean;
private onInstalledReason: string = null;
formPromise: Promise<AuthResult>;
onSuccessfulLoginNavigate: () => Promise<any>;
onSuccessfulLoginTwoFactorNavigate: () => Promise<any>;
loggingIn = false;
private redirectUri = 'https://localhost:8080/sso-connector.html';
constructor(private main: MainBackground, private autofillService: AutofillService,
private cipherService: CipherService, private platformUtilsService: BrowserPlatformUtilsService,
private storageService: StorageService, private i18nService: I18nService,
private analytics: Analytics, private notificationsService: NotificationsService,
private systemService: SystemService, private vaultTimeoutService: VaultTimeoutService,
private syncService: SyncService, private authService: AuthService, private stateService: StateService,
private environmentService: EnvironmentService) {
private environmentService: EnvironmentService, private popupUtilsService : PopupUtilsService) {
this.isSafari = this.platformUtilsService.isSafari();
this.runtime = this.isSafari ? {} : chrome.runtime;
@@ -62,7 +57,6 @@ export default class RuntimeBackground {
var vaultUrl = environmentService.webVaultUrl;
if(!vaultUrl) {
vaultUrl = 'https://vault.bitwarden.com';
// vaultUrl = 'https://localhost:8080';
}
if(!request.referrer) {
@@ -75,34 +69,13 @@ export default class RuntimeBackground {
if (request.type == "AUTH_RESULT") {
try {
this.initiateLogIn(request.code, request.codeVerifier);
popupUtilsService.ProcessSso(request.code, request.state);
}
catch { }
catch (error) { }
}
});
}
async initiateLogIn(code: string, codeVerifier: string) {
this.loggingIn = true;
try {
this.formPromise = this.authService.logInSso(code, codeVerifier, this.redirectUri);
const response = await this.formPromise;
if (response) {
this.syncService.fullSync(true);
this.main.openPopup();
var sidebarName : string = this.platformUtilsService.sidebarViewName();
var sidebarWindows = chrome.extension.getViews({ type: sidebarName });
if(sidebarWindows && sidebarWindows.length > 0) {
sidebarWindows[0].location.reload();
}
}
} catch(error) { }
this.loggingIn = false;
}
async init() {
if (!this.runtime) {
return;