2023-05-25 07:40:20 +02:00
|
|
|
import { useEffect, useState } from "react";
|
2023-04-20 20:51:46 +02:00
|
|
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
|
|
|
import type { KcContext } from "../kcContext";
|
|
|
|
import type { I18n } from "../i18n";
|
|
|
|
|
|
|
|
export default function SamlPostForm(props: PageProps<Extract<KcContext, { pageId: "saml-post-form.ftl" }>, I18n>) {
|
|
|
|
const { kcContext, i18n, doUseDefaultCss, Template, classes } = props;
|
|
|
|
|
|
|
|
const { msgStr, msg } = i18n;
|
|
|
|
|
|
|
|
const { samlPost } = kcContext;
|
2023-05-25 07:40:20 +02:00
|
|
|
|
|
|
|
const [htmlFormElement, setHtmlFormElement] = useState<HTMLFormElement | null>(null);
|
|
|
|
|
2023-05-02 16:17:53 +02:00
|
|
|
useEffect(() => {
|
2023-05-25 07:40:20 +02:00
|
|
|
if (htmlFormElement === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Storybook
|
|
|
|
if (samlPost.url === "") {
|
|
|
|
alert("In a real Keycloak the user would be redirected immediately");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
htmlFormElement.submit();
|
|
|
|
}, [htmlFormElement]);
|
2023-04-20 20:51:46 +02:00
|
|
|
return (
|
|
|
|
<Template {...{ kcContext, i18n, doUseDefaultCss, classes }} displayMessage={false} headerNode={msg("saml.post-form.title")}>
|
|
|
|
<p>{msg("saml.post-form.message")}</p>
|
2023-05-25 07:40:20 +02:00
|
|
|
<form name="saml-post-binding" method="post" action={samlPost.url} ref={setHtmlFormElement}>
|
2023-04-20 20:51:46 +02:00
|
|
|
{samlPost.SAMLRequest && <input type="hidden" name="SAMLRequest" value={samlPost.SAMLRequest} />}
|
|
|
|
{samlPost.SAMLResponse && <input type="hidden" name="SAMLResponse" value={samlPost.SAMLResponse} />}
|
2023-05-02 16:50:44 +03:00
|
|
|
{samlPost.relayState && <input type="hidden" name="RelayState" value={samlPost.relayState} />}
|
2023-04-20 20:51:46 +02:00
|
|
|
<noscript>
|
|
|
|
<p>{msg("saml.post-form.js-disabled")}</p>
|
|
|
|
<input type="submit" value={msgStr("doContinue")} />
|
|
|
|
</noscript>
|
|
|
|
</form>
|
|
|
|
</Template>
|
|
|
|
);
|
|
|
|
}
|