mirror of
https://github.com/bitwarden/clients.git
synced 2024-11-25 18:57:43 +01:00
PM-5384 - Refactor duo redirect connector to use messaging to communicate with browser extension similar to SSO process as BroadcastChannel can only communication on same origins (not web to browser extension). (#7736)
This commit is contained in:
parent
3a9dead640
commit
faabb3bbe9
1 changed files with 24 additions and 17 deletions
|
@ -8,29 +8,36 @@ window.addEventListener("load", () => {
|
|||
const client = getQsParam("client");
|
||||
const code = getQsParam("code");
|
||||
|
||||
if (client === "browser" || client === "web") {
|
||||
if (client === "web") {
|
||||
const channel = new BroadcastChannel("duoResult");
|
||||
|
||||
channel.postMessage({ code: code });
|
||||
channel.close();
|
||||
|
||||
const handOffMessage = ("; " + document.cookie)
|
||||
.split("; duoHandOffMessage=")
|
||||
.pop()
|
||||
.split(";")
|
||||
.shift();
|
||||
|
||||
document.cookie = "duoHandOffMessage=;SameSite=strict;max-age=0";
|
||||
|
||||
const content = document.getElementById("content");
|
||||
content.innerHTML = "";
|
||||
|
||||
const p = document.createElement("p");
|
||||
p.className = "text-center";
|
||||
p.innerText = handOffMessage;
|
||||
|
||||
content.appendChild(p);
|
||||
processAndDisplayHandoffMessage();
|
||||
} else if (client === "browser") {
|
||||
window.postMessage({ command: "duoResult", code: code }, "*");
|
||||
processAndDisplayHandoffMessage();
|
||||
} else if (client === "mobile" || client === "desktop") {
|
||||
document.location.replace(mobileDesktopCallback + "?code=" + encodeURIComponent(code));
|
||||
}
|
||||
});
|
||||
|
||||
function processAndDisplayHandoffMessage() {
|
||||
const handOffMessage = ("; " + document.cookie)
|
||||
.split("; duoHandOffMessage=")
|
||||
.pop()
|
||||
.split(";")
|
||||
.shift();
|
||||
|
||||
document.cookie = "duoHandOffMessage=;SameSite=strict;max-age=0";
|
||||
|
||||
const content = document.getElementById("content");
|
||||
content.innerHTML = "";
|
||||
|
||||
const p = document.createElement("p");
|
||||
p.className = "text-center";
|
||||
p.innerText = handOffMessage;
|
||||
|
||||
content.appendChild(p);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue