Add webauthn-error.ftl page

This commit is contained in:
Joseph Garrone 2024-05-11 19:18:52 +02:00
parent 1e50427d62
commit 94b618626d
4 changed files with 78 additions and 2 deletions

View File

@ -33,7 +33,8 @@ export const loginThemePageIds = [
"login-recovery-authn-code-config.ftl", "login-recovery-authn-code-config.ftl",
"login-recovery-authn-code-input.ftl", "login-recovery-authn-code-input.ftl",
"login-reset-otp.ftl", "login-reset-otp.ftl",
"login-x509-info.ftl" "login-x509-info.ftl",
"webauthn-error.ftl"
] as const; ] as const;
export const accountThemePageIds = [ export const accountThemePageIds = [

View File

@ -39,6 +39,7 @@ const LoginRecoveryAuthnCodeConfig = lazy(() => import("keycloakify/login/pages/
const LoginRecoveryAuthnCodeInput = lazy(() => import("keycloakify/login/pages/LoginRecoveryAuthnCodeInput")); const LoginRecoveryAuthnCodeInput = lazy(() => import("keycloakify/login/pages/LoginRecoveryAuthnCodeInput"));
const LoginResetOtp = lazy(() => import("keycloakify/login/pages/LoginResetOtp")); const LoginResetOtp = lazy(() => import("keycloakify/login/pages/LoginResetOtp"));
const LoginX509Info = lazy(() => import("keycloakify/login/pages/LoginX509Info")); const LoginX509Info = lazy(() => import("keycloakify/login/pages/LoginX509Info"));
const WebauthnError = lazy(() => import("keycloakify/login/pages/WebauthnError"));
type FallbackProps = PageProps<KcContext, I18n> & { type FallbackProps = PageProps<KcContext, I18n> & {
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>; UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
@ -119,6 +120,8 @@ export default function Fallback(props: FallbackProps) {
return <LoginResetOtp kcContext={kcContext} {...rest} />; return <LoginResetOtp kcContext={kcContext} {...rest} />;
case "login-x509-info.ftl": case "login-x509-info.ftl":
return <LoginX509Info kcContext={kcContext} {...rest} />; return <LoginX509Info kcContext={kcContext} {...rest} />;
case "webauthn-error.ftl":
return <WebauthnError kcContext={kcContext} {...rest} />;
} }
assert<Equals<typeof kcContext, never>>(false); assert<Equals<typeof kcContext, never>>(false);
})()} })()}

View File

@ -43,7 +43,8 @@ export type KcContext =
| KcContext.LoginRecoveryAuthnCodeConfig | KcContext.LoginRecoveryAuthnCodeConfig
| KcContext.LoginRecoveryAuthnCodeInput | KcContext.LoginRecoveryAuthnCodeInput
| KcContext.LoginResetOtp | KcContext.LoginResetOtp
| KcContext.LoginX509Info; | KcContext.LoginX509Info
| KcContext.WebauthnError;
assert<KcContext["themeType"] extends ThemeType ? true : false>(); assert<KcContext["themeType"] extends ThemeType ? true : false>();
@ -565,6 +566,11 @@ export declare namespace KcContext {
}; };
}; };
}; };
export type WebauthnError = Common & {
pageId: "webauthn-error.ftl";
isAppInitiatedAction?: boolean;
};
} }
export type UserProfile = { export type UserProfile = {

View File

@ -0,0 +1,66 @@
import type { PageProps } from "keycloakify/login/pages/PageProps";
import { clsx } from "keycloakify/tools/clsx";
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
import type { KcContext } from "../kcContext";
import type { I18n } from "../i18n";
export default function WebauthnError(props: PageProps<Extract<KcContext, { pageId: "webauthn-error.ftl" }>, I18n>) {
const { kcContext, i18n, doUseDefaultCss, Template, classes } = props;
const { url, isAppInitiatedAction } = kcContext;
const { msg, msgStr } = i18n;
const { getClassName } = useGetClassName({
doUseDefaultCss,
classes
});
return (
<Template {...{ kcContext, i18n, doUseDefaultCss, classes }} displayMessage headerNode={msg("webauthn-error-title")}>
<form id="kc-error-credential-form" className={getClassName("kcFormClass")} action={url.loginAction} method="post">
<input type="hidden" id="executionValue" name="authenticationExecution" />
<input type="hidden" id="isSetRetry" name="isSetRetry" />
</form>
<input
tabIndex={4}
onClick={() => {
// @ts-expect-error: Trusted Keycloak's code
document.getElementById("isSetRetry").value = "retry";
// @ts-expect-error: Trusted Keycloak's code
document.getElementById("executionValue").value = "${execution}";
// @ts-expect-error: Trusted Keycloak's code
document.getElementById("kc-error-credential-form").submit();
}}
type="button"
className={clsx(
getClassName("kcButtonClass"),
getClassName("kcButtonPrimaryClass"),
getClassName("kcButtonBlockClass"),
getClassName("kcButtonLargeClass")
)}
name="try-again"
id="kc-try-again"
value={msgStr("doTryAgain")}
/>
{isAppInitiatedAction && (
<form action={url.loginAction} className={getClassName("kcFormClass")} id="kc-webauthn-settings-form" method="post">
<button
type="submit"
className={clsx(
getClassName("kcButtonClass"),
getClassName("kcButtonDefaultClass"),
getClassName("kcButtonBlockClass"),
getClassName("kcButtonLargeClass")
)}
id="cancelWebAuthnAIA"
name="cancel-aia"
value="true"
>
{msgStr("doCancel")}
</button>
</form>
)}
</Template>
);
}