mirror of
https://github.com/bitwarden/browser
synced 2026-01-03 09:03:32 +00:00
2fa page for duo in safari
This commit is contained in:
42
src/2fa/2fa.ts
Normal file
42
src/2fa/2fa.ts
Normal 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
11
src/2fa/index.html
Normal 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>
|
||||
Reference in New Issue
Block a user