2021-03-16 17:44:31 +01:00
|
|
|
|
import { getQsParam } from "./common";
|
|
|
|
|
|
2020-07-16 15:18:25 +02:00
|
|
|
|
require("./sso.scss");
|
|
|
|
|
|
2022-02-24 12:10:07 +01:00
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
2020-07-16 15:18:25 +02:00
|
|
|
|
const code = getQsParam("code");
|
|
|
|
|
const state = getQsParam("state");
|
2020-08-20 21:30:22 +02:00
|
|
|
|
|
2020-11-24 18:29:04 +01:00
|
|
|
|
if (state != null && state.includes(":clientId=browser")) {
|
2020-08-20 21:30:22 +02:00
|
|
|
|
initiateBrowserSso(code, state);
|
2021-12-17 15:57:11 +01:00
|
|
|
|
} else {
|
2020-08-20 21:30:22 +02:00
|
|
|
|
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
|
2020-08-27 17:44:04 +02:00
|
|
|
|
// Match any characters between "_returnUri='" and the next "'"
|
|
|
|
|
const returnUri = extractFromRegex(state, "(?<=_returnUri=')(.*)(?=')");
|
|
|
|
|
if (returnUri) {
|
|
|
|
|
window.location.href = window.location.origin + `/#${returnUri}`;
|
2020-08-20 21:30:22 +02:00
|
|
|
|
} else {
|
2020-08-27 17:44:04 +02:00
|
|
|
|
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
|
2020-08-20 21:30:22 +02:00
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
}
|
2020-07-16 15:18:25 +02:00
|
|
|
|
});
|
|
|
|
|
|
2020-08-20 21:30:22 +02:00
|
|
|
|
function initiateBrowserSso(code: string, state: string) {
|
|
|
|
|
window.postMessage({ command: "authResult", code: code, state: state }, "*");
|
2020-12-14 19:27:32 +01:00
|
|
|
|
const handOffMessage = ("; " + document.cookie)
|
|
|
|
|
.split("; ssoHandOffMessage=")
|
|
|
|
|
.pop()
|
|
|
|
|
.split(";")
|
|
|
|
|
.shift();
|
|
|
|
|
document.cookie = "ssoHandOffMessage=;SameSite=strict;max-age=0";
|
2021-11-11 04:35:35 +01:00
|
|
|
|
const content = document.getElementById("content");
|
2021-11-09 18:15:58 +01:00
|
|
|
|
content.innerHTML = "";
|
2021-11-11 04:35:35 +01:00
|
|
|
|
const p = document.createElement("p");
|
2021-11-09 18:15:58 +01:00
|
|
|
|
p.innerText = handOffMessage;
|
|
|
|
|
content.appendChild(p);
|
2020-08-20 21:30:22 +02:00
|
|
|
|
}
|
2020-08-27 17:44:04 +02:00
|
|
|
|
|
|
|
|
|
function extractFromRegex(s: string, regexString: string) {
|
|
|
|
|
const regex = new RegExp(regexString);
|
|
|
|
|
const results = regex.exec(s);
|
|
|
|
|
|
|
|
|
|
if (!results) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results[0];
|
|
|
|
|
}
|