mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
Move web to apps/web and bitwarden_license/bit-web
This commit is contained in:
47
apps/web/src/connectors/sso.ts
Normal file
47
apps/web/src/connectors/sso.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { getQsParam } from "./common";
|
||||
|
||||
require("./sso.scss");
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const code = getQsParam("code");
|
||||
const state = getQsParam("state");
|
||||
|
||||
if (state != null && state.includes(":clientId=browser")) {
|
||||
initiateBrowserSso(code, state);
|
||||
} else {
|
||||
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
|
||||
// Match any characters between "_returnUri='" and the next "'"
|
||||
const returnUri = extractFromRegex(state, "(?<=_returnUri=')(.*)(?=')");
|
||||
if (returnUri) {
|
||||
window.location.href = window.location.origin + `/#${returnUri}`;
|
||||
} else {
|
||||
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function initiateBrowserSso(code: string, state: string) {
|
||||
window.postMessage({ command: "authResult", code: code, state: state }, "*");
|
||||
const handOffMessage = ("; " + document.cookie)
|
||||
.split("; ssoHandOffMessage=")
|
||||
.pop()
|
||||
.split(";")
|
||||
.shift();
|
||||
document.cookie = "ssoHandOffMessage=;SameSite=strict;max-age=0";
|
||||
const content = document.getElementById("content");
|
||||
content.innerHTML = "";
|
||||
const p = document.createElement("p");
|
||||
p.innerText = handOffMessage;
|
||||
content.appendChild(p);
|
||||
}
|
||||
|
||||
function extractFromRegex(s: string, regexString: string) {
|
||||
const regex = new RegExp(regexString);
|
||||
const results = regex.exec(s);
|
||||
|
||||
if (!results) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return results[0];
|
||||
}
|
||||
Reference in New Issue
Block a user