diff --git a/src/2fa/2fa.ts b/src/2fa/2fa.ts index 7e7e9c074a..f57824978a 100644 --- a/src/2fa/2fa.ts +++ b/src/2fa/2fa.ts @@ -31,10 +31,17 @@ document.addEventListener('DOMContentLoaded', () => { sigValue: sigElement.value, }, }); - window.close(); } }, }); + } else if (msg.data.type === 'success') { + safari.self.tab.dispatchMessage('bitwarden', { + command: 'openPopup', + }); + + setTimeout(() => { + window.close(); + }, 500); } else { // TODO: others like u2f? } diff --git a/src/2fa/index.html b/src/2fa/index.html index b5c78a8730..85fc6fcc77 100644 --- a/src/2fa/index.html +++ b/src/2fa/index.html @@ -3,9 +3,29 @@ Two-step Login + - -
Loading...
- + +
+ +
diff --git a/src/background/commands.background.ts b/src/background/commands.background.ts index 9fbf977726..f1b37bd5bb 100644 --- a/src/background/commands.background.ts +++ b/src/background/commands.background.ts @@ -93,12 +93,11 @@ export default class CommandsBackground { private async openPopup() { // Chrome APIs cannot open popup - if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) { + if (!this.isSafari) { return; } - safari.extension.toolbarItems[0].showPopover(); - + this.main.openPopup(); (window as any).ga('send', { hitType: 'event', eventAction: 'Opened Popup From Command', diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 8e6f6388bd..ca13676b5f 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -282,6 +282,21 @@ export default class MainBackground { this.runtimeBackground.processMessage(message, { tab: null }, () => { /* No response needed. */ }); } + async openPopup() { + // Chrome APIs cannot open popup + if (!this.isSafari || !safari.extension.toolbarItems || !safari.extension.toolbarItems.length) { + return; + } + + const activeToolBars = safari.extension.toolbarItems.filter((tb: any) => { + return tb.browserWindow === safari.application.activeBrowserWindow; + }); + + if (activeToolBars && activeToolBars.length) { + activeToolBars[0].showPopover(); + } + } + private async buildContextMenu() { if (this.isSafari || !chrome.contextMenus || this.buildingContextMenu) { return; diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 5b42a8beda..30aefc07a8 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -81,6 +81,9 @@ export default class RuntimeBackground { setTimeout(async () => await this.main.refreshBadgeAndMenu(), 2000); } break; + case 'openPopup': + await this.main.openPopup(); + break; case 'bgGetDataForTab': await this.getDataForTab(sender.tab, msg.responseCommand); break; diff --git a/src/popup/app/accounts/accountsLoginTwoFactorController.js b/src/popup/app/accounts/accountsLoginTwoFactorController.js index 8790e837cc..32665ce14e 100644 --- a/src/popup/app/accounts/accountsLoginTwoFactorController.js +++ b/src/popup/app/accounts/accountsLoginTwoFactorController.js @@ -9,6 +9,7 @@ angular }, 500); $scope.i18n = i18nService; + $scope.showNewWindowMessage = platformUtilsService.isSafari(); var customWebVaultUrl = null; if (environmentService.baseUrl) { @@ -54,7 +55,7 @@ angular init(); $scope.loginPromise = null; - $scope.login = function (token) { + $scope.login = function (token, sendSuccessToTab) { if (!token) { toastr.error(i18nService.verificationCodeRequired, i18nService.errorsOccurred); return; @@ -76,7 +77,18 @@ angular $scope.loginPromise = authService.logIn(email, masterPassword, $scope.providerType, token, $scope.remember.checked); $scope.loginPromise.then(function () { $analytics.eventTrack('Logged In From Two-step'); - $state.go('tabs.vault', { animation: 'in-slide-left', syncOnLoad: true }); + $state.go('tabs.vault', { animation: 'in-slide-left', syncOnLoad: true }).then(function(){ + if (sendSuccessToTab) { + $timeout(function() { + BrowserApi.tabSendMessage(sendSuccessToTab, { + command: '2faPageData', + data: { + type: 'success' + } + }); + }, 1000); + } + }); }, function () { u2f.start(); }); @@ -126,7 +138,7 @@ angular console.log('got 2fa response'); console.log(details); if (details.type === 'duo') { - $scope.login(details.data.sigValue); + $scope.login(details.data.sigValue, details.tab); } }); @@ -174,7 +186,7 @@ angular signature: params.Signature } }); - }, 1000); + }, 500); } else { $window.Duo.init({ diff --git a/src/popup/app/accounts/views/accountsLoginTwoFactor.html b/src/popup/app/accounts/views/accountsLoginTwoFactor.html index 30e4dfb6e7..a7cbe79b35 100644 --- a/src/popup/app/accounts/views/accountsLoginTwoFactor.html +++ b/src/popup/app/accounts/views/accountsLoginTwoFactor.html @@ -52,9 +52,12 @@
Duo
-
+
+
+
Complete your two-step login request using the new window.
+
diff --git a/src/popup/app/global/main.controller.ts b/src/popup/app/global/main.controller.ts index 7e88ea4361..3c5adbac7d 100644 --- a/src/popup/app/global/main.controller.ts +++ b/src/popup/app/global/main.controller.ts @@ -26,8 +26,6 @@ export class MainController implements ng.IController { }); $window.bitwardenPopupMainMessageListener = (msg: any, sender: any, sendResponse: any) => { - console.log(msg); - if (msg.command === 'syncCompleted') { $scope.$broadcast('syncCompleted', msg.successfully); } else if (msg.command === 'syncStarted') { @@ -51,6 +49,7 @@ export class MainController implements ng.IController { $scope.$broadcast('2faPageResponse', { type: msg.type, data: msg.data, + tab: sender.tab, }); } }; diff --git a/src/popup/less/components.less b/src/popup/less/components.less index cbfa48b958..a5e541a0cc 100644 --- a/src/popup/less/components.less +++ b/src/popup/less/components.less @@ -587,6 +587,11 @@ } } +.two-step-window-message { + text-align: center; + margin: 30px 0 20px 0; +} + #duoFrameWrapper { background: ~"url('../images/loading.svg') 0 0 no-repeat"; width: 100%;