2020-05-15 19:06:24 +01:00
|
|
|
function getUrlParams(hash, start) {
|
2021-04-15 16:54:43 +01:00
|
|
|
const hashes = hash.slice(hash.indexOf(start) + 1).split("&");
|
2020-05-15 19:06:24 +01:00
|
|
|
|
|
|
|
if (!hashes || hashes.length === 0 || hashes[0] === "") {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-04-15 16:54:43 +01:00
|
|
|
const params = {};
|
|
|
|
hashes.map((hash) => {
|
|
|
|
const [key, val] = hash.split("=");
|
|
|
|
params[key] = decodeURIComponent(val);
|
|
|
|
});
|
|
|
|
return params;
|
2020-05-15 19:06:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleImplicitGrant() {
|
2021-04-15 16:54:43 +01:00
|
|
|
const params = getUrlParams(window.location.hash, "#");
|
2020-05-15 19:06:24 +01:00
|
|
|
if (!params) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
params.request_type = "token";
|
|
|
|
|
|
|
|
console.log("Sent request_type token to server", params);
|
2021-04-15 16:54:43 +01:00
|
|
|
fetch("?" + new URLSearchParams(params).toString(), {
|
|
|
|
method: "POST",
|
2020-05-15 19:06:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
handleImplicitGrant();
|
|
|
|
|
|
|
|
function handleAuthenticationCode() {
|
2021-04-15 16:54:43 +01:00
|
|
|
const params = getUrlParams(window.location.search, "?");
|
2020-05-15 19:06:24 +01:00
|
|
|
if (!params) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
params.request_type = "code";
|
|
|
|
|
|
|
|
console.log("Sent request_type code to server", params);
|
2021-04-15 16:54:43 +01:00
|
|
|
fetch("?" + new URLSearchParams(params).toString(), {
|
|
|
|
method: "POST",
|
2020-05-15 19:06:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
handleAuthenticationCode();
|
|
|
|
|
2021-04-15 16:54:43 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
const errorContainer = document.querySelector("#error");
|
|
|
|
const successContainer = document.querySelector("#success");
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
|
|
|
if (params.has("error")) {
|
|
|
|
errorContainer.classList.remove("hidden");
|
|
|
|
} else {
|
|
|
|
successContainer.classList.remove("hidden");
|
|
|
|
}
|
|
|
|
});
|