From 3b560fca2211a86c3150ca728619b5cb95e20485 Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 14 Aug 2020 15:20:16 -0500 Subject: [PATCH] Implemented feedback --- src/background/runtime.background.ts | 46 +++++++++++------------ src/content/sso.ts | 4 +- src/popup/accounts/sso.component.ts | 14 +------ src/popup/services/popup-utils.service.ts | 8 ---- 4 files changed, 24 insertions(+), 48 deletions(-) diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index ecb0aa3955..3eb8ed350a 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -4,7 +4,6 @@ import { CipherView } from 'jslib/models/view/cipherView'; import { LoginUriView } from 'jslib/models/view/loginUriView'; import { LoginView } from 'jslib/models/view/loginView'; -import { AuthResult } from 'jslib/models/domain/authResult'; import { AuthService } from 'jslib/abstractions/auth.service'; import { AutofillService } from '../services/abstractions/autofill.service'; import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; @@ -50,30 +49,6 @@ export default class RuntimeBackground { this.onInstalledReason = details.reason; }); } - - chrome.runtime.onMessage.addListener( - (request: any) => { - - var vaultUrl = environmentService.webVaultUrl; - if(!vaultUrl) { - vaultUrl = 'https://vault.bitwarden.com'; - } - - if(!request.referrer) { - return; - } - - if(!vaultUrl.includes(request.referrer)) { - return; - } - - if (request.type == "AUTH_RESULT") { - try { - popupUtilsService.ProcessSso(request.code, request.state); - } - catch (error) { } - } - }); } async init() { @@ -189,6 +164,27 @@ export default class RuntimeBackground { break; } break; + case 'authResult': + var vaultUrl = this.environmentService.webVaultUrl; + if(!vaultUrl) { + vaultUrl = 'https://vault.bitwarden.com'; + } + + if(!msg.referrer) { + return; + } + + if(!vaultUrl.includes(msg.referrer)) { + return; + } + + try { + chrome.tabs.create({ + url: 'popup/index.html?uilocation=popout#/sso?code=' + msg.code + '&state=' + msg.state + }); + } + catch { } + break; default: break; } diff --git a/src/content/sso.ts b/src/content/sso.ts index 70ebd0ec22..cc936d91ab 100644 --- a/src/content/sso.ts +++ b/src/content/sso.ts @@ -2,9 +2,9 @@ window.addEventListener("message", function(event) { if (event.source != window) return; - if (event.data.type && (event.data.type == "AUTH_RESULT")) { + if (event.data.command && (event.data.command == "authResult")) { chrome.runtime.sendMessage({ - type: event.data.type, + command: event.data.command, code: event.data.code, state: event.data.state, referrer: event.source.location.hostname diff --git a/src/popup/accounts/sso.component.ts b/src/popup/accounts/sso.component.ts index 1a0e4a83c6..8a3116e690 100644 --- a/src/popup/accounts/sso.component.ts +++ b/src/popup/accounts/sso.component.ts @@ -9,7 +9,6 @@ import { ApiService } from 'jslib/abstractions/api.service'; import { AuthService } from 'jslib/abstractions/auth.service'; import BrowserPlatformUtilsService from '../../services/browserPlatformUtils.service'; import { CryptoFunctionService } from 'jslib/abstractions/cryptoFunction.service'; -import { ConstantsService } from 'jslib/services/constants.service'; import { EnvironmentService } from 'jslib/abstractions/environment.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; @@ -30,8 +29,7 @@ export class SsoComponent extends BaseSsoComponent { storageService: StorageService, stateService: StateService, platformUtilsService: PlatformUtilsService, apiService: ApiService, cryptoFunctionService: CryptoFunctionService, passwordGenerationService: PasswordGenerationService, - syncService: SyncService, private browserPlatformUtilsService: BrowserPlatformUtilsService, - private environmentService: EnvironmentService ) { + syncService: SyncService, private environmentService: EnvironmentService ) { super(authService, router, i18nService, route, storageService, stateService, platformUtilsService, apiService, cryptoFunctionService, passwordGenerationService); @@ -44,17 +42,7 @@ export class SsoComponent extends BaseSsoComponent { this.clientId = 'browser'; super.onSuccessfulLogin = () => { - var sidebarName : string = this.browserPlatformUtilsService.sidebarViewName(); - var sidebarWindows = chrome.extension.getViews({ type: sidebarName }); - if(sidebarWindows && sidebarWindows.length > 0) { - sidebarWindows[0].location.reload(); - } - return syncService.fullSync(true); }; - - super.onSuccessfulLoginTwoFactorNavigate = () => { - return router.navigate(['2fa']); - } } } diff --git a/src/popup/services/popup-utils.service.ts b/src/popup/services/popup-utils.service.ts index c7d7f01d45..2faca3dea7 100644 --- a/src/popup/services/popup-utils.service.ts +++ b/src/popup/services/popup-utils.service.ts @@ -78,12 +78,4 @@ export class PopupUtilsService { // Safari can't open popup in full page tab :( } } - - ProcessSso(code: string, state: string) - { - // Redirect to SSO token validation. - chrome.tabs.create({ - url: 'popup/index.html?uilocation=popout#/sso?code=' + code + '&state=' + state - }); - } }