1
0
mirror of https://github.com/bitwarden/web synced 2026-01-03 00:53:34 +00:00
Files
web/src/connectors/duo.ts
2022-02-24 12:10:07 +01:00

48 lines
1.1 KiB
TypeScript

import * as DuoWebSDK from "duo_web_sdk";
import { getQsParam } from "./common";
require("./duo.scss");
document.addEventListener("DOMContentLoaded", () => {
const frameElement = document.createElement("iframe");
frameElement.setAttribute("id", "duo_iframe");
setFrameHeight();
document.body.appendChild(frameElement);
const hostParam = getQsParam("host");
const requestParam = getQsParam("request");
const hostUrl = new URL("https://" + hostParam);
if (
!hostUrl.hostname.endsWith(".duosecurity.com") &&
!hostUrl.hostname.endsWith(".duofederal.com")
) {
return;
}
DuoWebSDK.init({
iframe: "duo_iframe",
host: hostParam,
sig_request: requestParam,
submit_callback: (form: any) => {
invokeCSCode(form.elements.sig_response.value);
},
});
window.onresize = setFrameHeight;
function setFrameHeight() {
frameElement.style.height = window.innerHeight + "px";
}
});
function invokeCSCode(data: string) {
try {
(window as any).invokeCSharpAction(data);
} catch (err) {
// eslint-disable-next-line
console.log(err);
}
}