Use a hidden form to do POST
based logout (#34694)
Closes #32648 Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
a9c3e592f3
commit
b2930a4799
1 changed files with 24 additions and 21 deletions
|
@ -1299,30 +1299,33 @@ function Keycloak (config) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const logoutUrl = kc.createLogoutUrl(options);
|
// Create form to send POST request.
|
||||||
const response = await fetch(logoutUrl, {
|
const form = document.createElement("form");
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
|
||||||
},
|
|
||||||
body: new URLSearchParams({
|
|
||||||
id_token_hint: kc.idToken,
|
|
||||||
client_id: kc.clientId,
|
|
||||||
post_logout_redirect_uri: adapter.redirectUri(options, false)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.redirected) {
|
form.setAttribute("method", "POST");
|
||||||
window.location.href = response.url;
|
form.setAttribute("action", kc.createLogoutUrl(options));
|
||||||
return;
|
form.style.display = "none";
|
||||||
|
|
||||||
|
// Add data to form as hidden input fields.
|
||||||
|
const data = {
|
||||||
|
id_token_hint: kc.idToken,
|
||||||
|
client_id: kc.clientId,
|
||||||
|
post_logout_redirect_uri: adapter.redirectUri(options, false)
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const [name, value] of Object.entries(data)) {
|
||||||
|
const input = document.createElement("input");
|
||||||
|
|
||||||
|
input.setAttribute("type", "hidden");
|
||||||
|
input.setAttribute("name", name);
|
||||||
|
input.setAttribute("value", value);
|
||||||
|
|
||||||
|
form.appendChild(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.ok) {
|
// Append form to page and submit it to perform logout and redirect.
|
||||||
window.location.reload();
|
document.body.appendChild(form);
|
||||||
return;
|
form.submit();
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error("Logout failed, request returned an error code.");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
register: async function(options) {
|
register: async function(options) {
|
||||||
|
|
Loading…
Reference in a new issue