1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-12 14:23:32 +00:00

2fa page for duo in safari

This commit is contained in:
Kyle Spearrin
2018-01-18 14:40:23 -05:00
parent bdc3eb559c
commit a3d3aac8be
7 changed files with 97 additions and 12 deletions

View File

@@ -28,7 +28,8 @@ const filters = {
], ],
safari: [ safari: [
'!build/safari/**/*', '!build/safari/**/*',
'!build/downloader/**/*' '!build/downloader/**/*',
'!build/2fa/**/*'
], ],
webExt: [ webExt: [
'!build/manifest.json' '!build/manifest.json'

42
src/2fa/2fa.ts Normal file
View File

@@ -0,0 +1,42 @@
require('../scripts/duo.js');
document.addEventListener('DOMContentLoaded', () => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (!isSafari) {
return;
}
safari.self.addEventListener('message', (msgEvent: any) => {
init2fa(msgEvent.message);
}, false);
function init2fa(msg: any) {
if (msg.command !== '2faPageData' || !msg.data) {
return;
}
if (msg.data.type === 'duo') {
(window as any).Duo.init({
host: msg.data.host,
sig_request: msg.data.signature,
submit_callback: (theForm: Document) => {
const sigElement = theForm.querySelector('input[name="sig_response"]');
if (sigElement) {
safari.self.tab.dispatchMessage('bitwarden', {
command: '2faPageResponse',
type: 'duo',
data: {
sigValue: sigElement.nodeValue,
},
});
window.close();
}
}
});
} else {
// TODO: others like u2f?
}
}
});

11
src/2fa/index.html Normal file
View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Two-step Login</title>
<meta charset="utf-8" />
</head>
<body style="padding: 30px; text-align: center; font-family: Arial; font-size: 18px;">
<div id="loading-message">Loading...</div>
<iframe id="duo_iframe"></iframe>
</body>
</html>

View File

@@ -228,7 +228,7 @@ class BrowserApi {
} }
} }
private static makeTabObject(tab: any): any { static makeTabObject(tab: any): any {
if (BrowserApi.isChromeApi) { if (BrowserApi.isChromeApi) {
return tab; return tab;
} }

View File

@@ -122,6 +122,12 @@ angular
u2f = null; u2f = null;
}); });
$scope.$on('2faPageResponse', (event, details) => {
if (details.type === 'duo') {
$scope.login(details.data.sigValue);
}
});
function getDefaultProvider(twoFactorProviders) { function getDefaultProvider(twoFactorProviders) {
var keys = Object.keys(twoFactorProviders); var keys = Object.keys(twoFactorProviders);
var providerType = null; var providerType = null;
@@ -154,7 +160,20 @@ angular
var params; var params;
if ($scope.providerType === constants.twoFactorProvider.duo) { if ($scope.providerType === constants.twoFactorProvider.duo) {
params = providers[constants.twoFactorProvider.duo]; params = providers[constants.twoFactorProvider.duo];
if (platformUtilsService.isSafari()) {
var tab = BrowserApi.createNewTab(BrowserApi.getAssetUrl('2fa/index.html'));
var tabToSend = BrowserApi.makeTabObject(tab);
$timeout(() => {
BrowserApi.tabSendMessage(tabToSend, {
command: '2faPageData',
data: {
host: params.Host,
signature: params.Signature
}
});
}, 1000);
}
else {
$window.Duo.init({ $window.Duo.init({
host: params.Host, host: params.Host,
sig_request: params.Signature, sig_request: params.Signature,
@@ -166,6 +185,7 @@ angular
} }
}); });
} }
}
else if ($scope.providerType === constants.twoFactorProvider.u2f) { else if ($scope.providerType === constants.twoFactorProvider.u2f) {
params = providers[constants.twoFactorProvider.u2f]; params = providers[constants.twoFactorProvider.u2f];
var challenges = JSON.parse(params.Challenges); var challenges = JSON.parse(params.Challenges);

View File

@@ -45,6 +45,11 @@ export class MainController implements ng.IController {
tab: msg.tab, tab: msg.tab,
details: msg.details, details: msg.details,
}); });
} else if (msg.command === '2faPageResponse') {
$scope.$broadcast('2faPageResponse', {
type: msg.type,
data: msg.data,
});
} }
}; };

View File

@@ -24,6 +24,7 @@ module.exports = {
'content/shortcuts': './src/content/shortcuts.js', 'content/shortcuts': './src/content/shortcuts.js',
'notification/bar': './src/notification/bar.js', 'notification/bar': './src/notification/bar.js',
'downloader/downloader': './src/downloader/downloader.ts', 'downloader/downloader': './src/downloader/downloader.ts',
'2fa/2fa': './src/2fa/2fa.ts',
}, },
module: { module: {
rules: [ rules: [
@@ -101,6 +102,11 @@ module.exports = {
filename: 'downloader/index.html', filename: 'downloader/index.html',
chunks: ['downloader/downloader'] chunks: ['downloader/downloader']
}), }),
new HtmlWebpackPlugin({
template: './src/2fa/index.html',
filename: '2fa/index.html',
chunks: ['2fa/2fa']
}),
new CopyWebpackPlugin([ new CopyWebpackPlugin([
'./src/manifest.json', './src/manifest.json',
{ from: './src/_locales', to: '_locales' }, { from: './src/_locales', to: '_locales' },