Compare commits
108 Commits
v11.3.3
...
v11.3.9-rc
Author | SHA1 | Date | |
---|---|---|---|
25920c208d | |||
19da96113f | |||
6e584e809e | |||
4185188a5b | |||
4273322ed5 | |||
ba0532c95d | |||
3a2fe597ba | |||
dda77952a0 | |||
d2e518d96b | |||
f3a97b2538 | |||
cacd017244 | |||
f5b15a5ef6 | |||
de620dca56 | |||
8decf4a3c9 | |||
831326952b | |||
27da578446 | |||
2c1cca168f | |||
e498fb784b | |||
2917719315 | |||
9ed90995e4 | |||
0f99bb5bdc | |||
1f4d4473e4 | |||
5332001ff4 | |||
22241fd7ad | |||
ddeade9775 | |||
f1cb165bdd | |||
9873353990 | |||
b879569b81 | |||
c3e821088b | |||
dc4f386e7a | |||
a40810b364 | |||
1690629717 | |||
9a6a71c8bc | |||
d626699f08 | |||
6aa60e685b | |||
9910762abc | |||
182fb430f1 | |||
bda20e2fbe | |||
bc586eceef | |||
128b27221a | |||
2dfb4eda9d | |||
fed6af4dfe | |||
c4ee6cd85c | |||
8fc307bd8d | |||
9e9ffcd586 | |||
49b064b5f2 | |||
ef6f5a4c23 | |||
e92562fd44 | |||
fe65ddb5f8 | |||
ffd405c6db | |||
9e41868e0d | |||
ca6accc889 | |||
dfe2e1562a | |||
ab43bb73d7 | |||
22b0b95e54 | |||
290ad8b592 | |||
d5519dbb55 | |||
4de9e059e9 | |||
e573aff6ae | |||
908e083dee | |||
ec29724997 | |||
88756e9807 | |||
80d8a0c4e3 | |||
7241f0c741 | |||
8565eb3fb8 | |||
87198f6e56 | |||
fa934da442 | |||
6c4dc711d2 | |||
1f2a755a97 | |||
a0e3dc163a | |||
810dc6ceb5 | |||
7203c742be | |||
2fd04cfb61 | |||
9c44d13f73 | |||
d6436a58a2 | |||
613167f3a6 | |||
ab0c281d98 | |||
c84dc281a2 | |||
835833a61b | |||
9af542ec89 | |||
06e33196bb | |||
36dd324139 | |||
52d4fe920c | |||
0d090d50d4 | |||
e57232edde | |||
dfe1e7ddd1 | |||
5ffc42c9db | |||
c63648a1b0 | |||
80fd4095c4 | |||
31d7a938f2 | |||
ee1b6868f8 | |||
7c7e5544e4 | |||
06fe26fbe7 | |||
c932c7d8f6 | |||
d56c536446 | |||
f5a9a28124 | |||
b86039536e | |||
59c4675e8a | |||
fbf6a329df | |||
ddec3118a4 | |||
94e2786297 | |||
ecfdff5454 | |||
c598a58ec9 | |||
3e38beb190 | |||
61a86e8e82 | |||
9c8e127fa0 | |||
5892cf2ba7 | |||
c9d7fc1b6e |
@ -290,6 +290,25 @@
|
||||
"code",
|
||||
"test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "nima70",
|
||||
"name": "Nima Shokouhfar",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/5094767?v=4",
|
||||
"profile": "https://github.com/nima70",
|
||||
"contributions": [
|
||||
"code",
|
||||
"test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "marvinruder",
|
||||
"name": "Marvin A. Ruder",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/18495294?v=4",
|
||||
"profile": "https://mruder.dev",
|
||||
"contributions": [
|
||||
"bug"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
32
README.md
32
README.md
@ -50,19 +50,41 @@ Keycloakify is fully compatible with Keycloak from version 11 to 26...[and beyon
|
||||
|
||||
## Sponsors
|
||||
|
||||
Friends for the project, we trust and recommend their services.
|
||||
Project backers, we trust and recommend their services.
|
||||
|
||||
<br/>
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
||||
<p align="center">
|
||||
<i><a href="https://phasetwo.io/?utm_source=keycloakify"><strong>Keycloak as a Service</strong></a> - Keycloak community contributors of popular <a href="https://github.com/p2-inc#our-extensions-?utm_source=keycloakify">extensions</a> providing free and dedicated <a href="https://phasetwo.io/hosting/?utm_source=keycloakify">Keycloak hosting</a> and enterprise <a href="https://phasetwo.io/support/?utm_source=keycloakify">Keycloak support</a> to businesses of all sizes.</i>
|
||||
</p>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
@ -87,7 +109,7 @@ Friends for the project, we trust and recommend their services.
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://cloud-iam.com/?mtm_campaign=keycloakify-deal&mtm_source=keycloakify-github"><strong>Managed Keycloak Provider</strong> - With Cloud-IAM powering your Keycloak clusters, you can sleep easy knowing you've got the software and the experts you need for operational excellence. </a>
|
||||
<a href="https://cloud-iam.com/?mtm_campaign=keycloakify-deal&mtm_source=keycloakify-github"><strong>Managed Keycloak Provider</strong> - With Cloud-IAM powering your Keycloak clusters, you can sleep easy knowing you've got the software and the experts you need for operational excellence. Cloud IAM is a french company. </a>
|
||||
<br/>
|
||||
Use code <code>keycloakify5</code> at checkout for a 5% discount.
|
||||
</p>
|
||||
@ -141,6 +163,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/oes-rioniz/"><img src="https://avatars.githubusercontent.com/u/5172296?v=4?s=100" width="100px;" alt="Omid"/><br /><sub><b>Omid</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=uchar" title="Tests">⚠️</a> <a href="https://github.com/keycloakify/keycloakify/commits?author=uchar" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kathari00"><img src="https://avatars.githubusercontent.com/u/42547712?v=4?s=100" width="100px;" alt="Katharina Eiserfey"/><br /><sub><b>Katharina Eiserfey</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=kathari00" title="Code">💻</a> <a href="https://github.com/keycloakify/keycloakify/commits?author=kathari00" title="Tests">⚠️</a> <a href="https://github.com/keycloakify/keycloakify/commits?author=kathari00" title="Documentation">📖</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/luca-peruzzo"><img src="https://avatars.githubusercontent.com/u/69015314?v=4?s=100" width="100px;" alt="Luca Peruzzo"/><br /><sub><b>Luca Peruzzo</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=luca-peruzzo" title="Code">💻</a> <a href="https://github.com/keycloakify/keycloakify/commits?author=luca-peruzzo" title="Tests">⚠️</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nima70"><img src="https://avatars.githubusercontent.com/u/5094767?v=4?s=100" width="100px;" alt="Nima Shokouhfar"/><br /><sub><b>Nima Shokouhfar</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/commits?author=nima70" title="Code">💻</a> <a href="https://github.com/keycloakify/keycloakify/commits?author=nima70" title="Tests">⚠️</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://mruder.dev"><img src="https://avatars.githubusercontent.com/u/18495294?v=4?s=100" width="100px;" alt="Marvin A. Ruder"/><br /><sub><b>Marvin A. Ruder</b></sub></a><br /><a href="https://github.com/keycloakify/keycloakify/issues?q=author%3Amarvinruder" title="Bug reports">🐛</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "11.3.3",
|
||||
"version": "11.3.9-rc.1",
|
||||
"description": "Framework to create custom Keycloak UIs",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -5,6 +5,7 @@ import * as fs from "fs";
|
||||
import chalk from "chalk";
|
||||
import { z } from "zod";
|
||||
import { id } from "tsafe/id";
|
||||
import { is } from "tsafe/is";
|
||||
|
||||
export type BuildContextLike = {
|
||||
bundler: BuildContext["bundler"];
|
||||
@ -83,6 +84,8 @@ export function updateAccountThemeImplementationInConfig(params: {
|
||||
|
||||
zParsedPackageJson.parse(parsedPackageJson);
|
||||
|
||||
assert(is<ParsedPackageJson>(parsedPackageJson));
|
||||
|
||||
return parsedPackageJson;
|
||||
})();
|
||||
|
||||
|
@ -5,6 +5,9 @@ import type { BuildContext } from "./shared/buildContext";
|
||||
import * as fs from "fs";
|
||||
import { downloadAndExtractArchive } from "./tools/downloadAndExtractArchive";
|
||||
import { maybeDelegateCommandToCustomHandler } from "./shared/customHandler_delegate";
|
||||
import fetch from "make-fetch-happen";
|
||||
import { SemVer } from "./tools/SemVer";
|
||||
import { assert } from "tsafe/assert";
|
||||
|
||||
export async function command(params: { buildContext: BuildContext }) {
|
||||
const { buildContext } = params;
|
||||
@ -36,7 +39,7 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
|
||||
console.log("Initialize with the base email theme from which version of Keycloak?");
|
||||
|
||||
const { keycloakVersion } = await promptKeycloakVersion({
|
||||
let { keycloakVersion } = await promptKeycloakVersion({
|
||||
// NOTE: This is arbitrary
|
||||
startingFromMajor: 17,
|
||||
excludeMajorVersions: [],
|
||||
@ -44,8 +47,32 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
buildContext
|
||||
});
|
||||
|
||||
const getUrl = (keycloakVersion: string) => {
|
||||
return `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`;
|
||||
};
|
||||
|
||||
keycloakVersion = await (async () => {
|
||||
const keycloakVersionParsed = SemVer.parse(keycloakVersion);
|
||||
|
||||
while (true) {
|
||||
const url = getUrl(SemVer.stringify(keycloakVersionParsed));
|
||||
|
||||
const response = await fetch(url, buildContext.fetchOptions);
|
||||
|
||||
if (response.ok) {
|
||||
break;
|
||||
}
|
||||
|
||||
assert(keycloakVersionParsed.patch !== 0);
|
||||
|
||||
keycloakVersionParsed.patch--;
|
||||
}
|
||||
|
||||
return SemVer.stringify(keycloakVersionParsed);
|
||||
})();
|
||||
|
||||
const { extractedDirPath } = await downloadAndExtractArchive({
|
||||
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
||||
url: getUrl(keycloakVersion),
|
||||
cacheDirPath: buildContext.cacheDirPath,
|
||||
fetchOptions: buildContext.fetchOptions,
|
||||
uniqueIdOfOnArchiveFile: "extractOnlyEmailTheme",
|
||||
|
@ -508,6 +508,15 @@ export function getBuildContext(params: {
|
||||
return themeNames;
|
||||
})();
|
||||
|
||||
const relativePathsCwd = (() => {
|
||||
switch (bundler) {
|
||||
case "vite":
|
||||
return projectDirPath;
|
||||
case "webpack":
|
||||
return pathDirname(packageJsonFilePath);
|
||||
}
|
||||
})();
|
||||
|
||||
const projectBuildDirPath = (() => {
|
||||
webpack: {
|
||||
if (bundler !== "webpack") {
|
||||
@ -519,7 +528,7 @@ export function getBuildContext(params: {
|
||||
if (parsedPackageJson.keycloakify.projectBuildDirPath !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: parsedPackageJson.keycloakify.projectBuildDirPath,
|
||||
cwd: projectDirPath
|
||||
cwd: relativePathsCwd
|
||||
});
|
||||
}
|
||||
|
||||
@ -563,7 +572,7 @@ export function getBuildContext(params: {
|
||||
if (buildOptions.keycloakifyBuildDirPath !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: buildOptions.keycloakifyBuildDirPath,
|
||||
cwd: projectDirPath
|
||||
cwd: relativePathsCwd
|
||||
});
|
||||
}
|
||||
|
||||
@ -592,7 +601,7 @@ export function getBuildContext(params: {
|
||||
if (parsedPackageJson.keycloakify.publicDirPath !== undefined) {
|
||||
return getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: parsedPackageJson.keycloakify.publicDirPath,
|
||||
cwd: projectDirPath
|
||||
cwd: relativePathsCwd
|
||||
});
|
||||
}
|
||||
|
||||
@ -664,7 +673,7 @@ export function getBuildContext(params: {
|
||||
pathIsh:
|
||||
parsedPackageJson.keycloakify
|
||||
.staticDirPathInProjectBuildDirPath,
|
||||
cwd: projectBuildDirPath
|
||||
cwd: relativePathsCwd
|
||||
});
|
||||
}
|
||||
|
||||
@ -992,7 +1001,7 @@ export function getBuildContext(params: {
|
||||
type: "path",
|
||||
path: getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: urlOrPath,
|
||||
cwd: projectDirPath
|
||||
cwd: relativePathsCwd
|
||||
})
|
||||
};
|
||||
}
|
||||
@ -1002,7 +1011,7 @@ export function getBuildContext(params: {
|
||||
? undefined
|
||||
: getAbsoluteAndInOsFormatPath({
|
||||
pathIsh: buildOptions.startKeycloakOptions.realmJsonFilePath,
|
||||
cwd: projectDirPath
|
||||
cwd: relativePathsCwd
|
||||
}),
|
||||
port: buildOptions.startKeycloakOptions?.port
|
||||
}
|
||||
|
@ -396,12 +396,12 @@ export async function command(params: {
|
||||
...(realmJsonFilePath === undefined
|
||||
? []
|
||||
: [
|
||||
`-v${SPACE_PLACEHOLDER}".${pathSep}${pathRelative(process.cwd(), realmJsonFilePath)}":/opt/keycloak/data/import/myrealm-realm.json`
|
||||
`-v${SPACE_PLACEHOLDER}"${realmJsonFilePath}":/opt/keycloak/data/import/myrealm-realm.json`
|
||||
]),
|
||||
`-v${SPACE_PLACEHOLDER}".${pathSep}${pathRelative(process.cwd(), jarFilePath_cacheDir)}":/opt/keycloak/providers/keycloak-theme.jar`,
|
||||
`-v${SPACE_PLACEHOLDER}"${jarFilePath_cacheDir}":/opt/keycloak/providers/keycloak-theme.jar`,
|
||||
...extensionJarFilePaths.map(
|
||||
jarFilePath =>
|
||||
`-v${SPACE_PLACEHOLDER}".${pathSep}${pathRelative(process.cwd(), jarFilePath)}":/opt/keycloak/providers/${pathBasename(jarFilePath)}`
|
||||
`-v${SPACE_PLACEHOLDER}"${jarFilePath}":/opt/keycloak/providers/${pathBasename(jarFilePath)}`
|
||||
),
|
||||
...(keycloakMajorVersionNumber <= 20
|
||||
? [`-e${SPACE_PLACEHOLDER}JAVA_OPTS=-Dkeycloak.profile=preview`]
|
||||
@ -424,7 +424,7 @@ export async function command(params: {
|
||||
}))
|
||||
.map(
|
||||
({ localDirPath, containerDirPath }) =>
|
||||
`-v${SPACE_PLACEHOLDER}".${pathSep}${pathRelative(process.cwd(), localDirPath)}":${containerDirPath}:rw`
|
||||
`-v${SPACE_PLACEHOLDER}"${localDirPath}":${containerDirPath}:rw`
|
||||
),
|
||||
...buildContext.environmentVariables
|
||||
.map(({ name }) => ({ name, envValue: process.env[name] }))
|
||||
|
@ -94,6 +94,7 @@ export declare namespace KcContext {
|
||||
languageTag: string;
|
||||
}[];
|
||||
currentLanguageTag: string;
|
||||
rtl?: boolean;
|
||||
};
|
||||
auth?: {
|
||||
showUsername?: boolean;
|
||||
|
@ -19,6 +19,7 @@ export type KcContextLike = {
|
||||
locale?: {
|
||||
currentLanguageTag: string;
|
||||
supported: { languageTag: string; url: string; label: string }[];
|
||||
rtl?: boolean;
|
||||
};
|
||||
"x-keycloakify": {
|
||||
messages: Record<string, string>;
|
||||
@ -95,6 +96,49 @@ export function createGetI18n<
|
||||
const html = document.querySelector("html");
|
||||
assert(html !== null);
|
||||
html.lang = currentLanguageTag;
|
||||
|
||||
const isRtl = (() => {
|
||||
const { rtl } = kcContext.locale ?? {};
|
||||
|
||||
if (rtl !== undefined) {
|
||||
return rtl;
|
||||
}
|
||||
|
||||
return [
|
||||
/* spell-checker: disable */
|
||||
// Common RTL languages
|
||||
"ar", // Arabic
|
||||
"fa", // Persian (Farsi)
|
||||
"he", // Hebrew
|
||||
"ur", // Urdu
|
||||
"ps", // Pashto
|
||||
"syr", // Syriac
|
||||
"dv", // Divehi (Maldivian)
|
||||
"ku", // Kurdish (Sorani)
|
||||
"ug", // Uighur
|
||||
"az", // Azerbaijani (Arabic script)
|
||||
"sd", // Sindhi
|
||||
|
||||
// Less common RTL languages
|
||||
"yi", // Yiddish
|
||||
"ha", // Hausa (when written in Arabic script)
|
||||
"ks", // Kashmiri (written in the Perso-Arabic script)
|
||||
"bal", // Balochi (when written in Arabic script)
|
||||
"khw", // Khowar (Chitrali)
|
||||
"brh", // Brahui (when written in Arabic script)
|
||||
"tmh", // Tamashek (some dialects use Arabic script)
|
||||
"bgn", // Western Balochi
|
||||
"arc", // Aramaic
|
||||
"sam", // Samaritan Aramaic
|
||||
"prd", // Parsi-Dari (a dialect of Persian)
|
||||
"huz", // Hazaragi (a dialect of Persian)
|
||||
"gbz", // Zaza (written in Arabic script in some areas)
|
||||
"urj" // Urdu in Romanized script (not always RTL, but to account for edge cases)
|
||||
/* spell-checker: enable */
|
||||
].includes(currentLanguageTag);
|
||||
})();
|
||||
|
||||
html.dir = isRtl ? "rtl" : "ltr";
|
||||
}
|
||||
|
||||
const getLanguageLabel = (languageTag: LanguageTag) => {
|
||||
|
1559
src/login/lib/getUserProfileApi/getUserProfileApi.ts
Normal file
1559
src/login/lib/getUserProfileApi/getUserProfileApi.ts
Normal file
File diff suppressed because it is too large
Load Diff
1
src/login/lib/getUserProfileApi/index.ts
Normal file
1
src/login/lib/getUserProfileApi/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./getUserProfileApi";
|
109
src/login/lib/getUserProfileApi/kcNumberUnFormat.ts
Normal file
109
src/login/lib/getUserProfileApi/kcNumberUnFormat.ts
Normal file
@ -0,0 +1,109 @@
|
||||
import { assert } from "keycloakify/tools/assert";
|
||||
let cleanup: (() => void) | undefined;
|
||||
const handledElements = new WeakSet<HTMLElement>();
|
||||
const KC_NUMBER_UNFORMAT = "kcNumberUnFormat";
|
||||
const SELECTOR = `input[data-${KC_NUMBER_UNFORMAT}]`;
|
||||
|
||||
export function unFormatNumberOnSubmit() {
|
||||
cleanup?.();
|
||||
|
||||
const handleElement = (element: HTMLInputElement) => {
|
||||
if (handledElements.has(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const form = element.closest("form");
|
||||
|
||||
if (form === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
form.addEventListener("submit", () => {
|
||||
const rawFormat = element.getAttribute(`data-${KC_NUMBER_UNFORMAT}`);
|
||||
if (rawFormat) {
|
||||
element.value = formatNumber(element.value, rawFormat);
|
||||
}
|
||||
});
|
||||
|
||||
handledElements.add(element);
|
||||
};
|
||||
|
||||
document.querySelectorAll(SELECTOR).forEach(element => {
|
||||
assert(element instanceof HTMLInputElement);
|
||||
handleElement(element);
|
||||
});
|
||||
|
||||
const observer = new MutationObserver(mutationsList => {
|
||||
for (const mutation of mutationsList) {
|
||||
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
|
||||
mutation.addedNodes.forEach(node => {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const element = (node as HTMLElement).querySelector(SELECTOR);
|
||||
if (element !== null) {
|
||||
assert(element instanceof HTMLInputElement);
|
||||
handleElement(element);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
cleanup = () => observer.disconnect();
|
||||
}
|
||||
|
||||
// NOTE: Keycloak code
|
||||
const formatNumber = (input: string, format: string) => {
|
||||
if (!input) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// array holding the patterns for the number of expected digits in each part
|
||||
const digitPattern = format.match(/{\d+}/g);
|
||||
|
||||
if (!digitPattern) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// calculate the maximum size of the given pattern based on the sum of the expected digits
|
||||
const maxSize = digitPattern.reduce(
|
||||
(total, p) => total + parseInt(p.replace("{", "").replace("}", "")),
|
||||
0
|
||||
);
|
||||
|
||||
// keep only digits
|
||||
let rawValue = input.replace(/\D+/g, "");
|
||||
|
||||
// make sure the value is a number
|
||||
//@ts-expect-error
|
||||
if (parseInt(rawValue) != rawValue) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// make sure the number of digits does not exceed the maximum size
|
||||
if (rawValue.length > maxSize) {
|
||||
rawValue = rawValue.substring(0, maxSize);
|
||||
}
|
||||
|
||||
// build the regex based based on the expected digits in each part
|
||||
const formatter = digitPattern.reduce((result, p) => result + `(\\d${p})`, "^");
|
||||
|
||||
// if the current digits match the pattern we have each group of digits in an array
|
||||
let digits = new RegExp(formatter).exec(rawValue);
|
||||
|
||||
// no match, return the raw value without any format
|
||||
if (!digits) {
|
||||
return input;
|
||||
}
|
||||
|
||||
let result = format;
|
||||
|
||||
// finally format the current digits accordingly to the given format
|
||||
for (let i = 0; i < digitPattern.length; i++) {
|
||||
result = result.replace(digitPattern[i], digits[i + 1]);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@ import { getKcClsx } from "keycloakify/login/lib/kcClsx";
|
||||
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
||||
import type { KcContext } from "../KcContext";
|
||||
import type { I18n } from "../i18n";
|
||||
import { kcSanitize } from "keycloakify/lib/kcSanitize";
|
||||
|
||||
export default function Code(props: PageProps<Extract<KcContext, { pageId: "code.ftl" }>, I18n>) {
|
||||
const { kcContext, i18n, doUseDefaultCss, Template, classes } = props;
|
||||
@ -30,7 +31,14 @@ export default function Code(props: PageProps<Extract<KcContext, { pageId: "code
|
||||
<input id="code" className={kcClsx("kcTextareaClass")} defaultValue={code.code} />
|
||||
</>
|
||||
) : (
|
||||
<p id="error">{code.error}</p>
|
||||
code.error && (
|
||||
<p
|
||||
id="error"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: kcSanitize(code.error)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</Template>
|
||||
|
@ -2,6 +2,7 @@ import { useEffect } from "react";
|
||||
import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags";
|
||||
import { assert } from "keycloakify/tools/assert";
|
||||
import { KcContext } from "keycloakify/login/KcContext/KcContext";
|
||||
import { waitForElementMountedOnDom } from "keycloakify/tools/waitForElementMountedOnDom";
|
||||
|
||||
type KcContextLike = {
|
||||
url: {
|
||||
@ -67,6 +68,12 @@ export function useScript(params: { authButtonId: string; kcContext: KcContextLi
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await waitForElementMountedOnDom({
|
||||
elementId: authButtonId
|
||||
});
|
||||
|
||||
insertScriptTags();
|
||||
})();
|
||||
}, [isFetchingTranslations]);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { useEffect } from "react";
|
||||
import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags";
|
||||
import { waitForElementMountedOnDom } from "keycloakify/tools/waitForElementMountedOnDom";
|
||||
|
||||
type I18nLike = {
|
||||
msgStr: (key: "recovery-codes-download-file-header" | "recovery-codes-download-file-description" | "recovery-codes-download-file-date") => string;
|
||||
@ -137,6 +138,12 @@ export function useScript(params: { olRecoveryCodesListId: string; i18n: I18nLik
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await waitForElementMountedOnDom({
|
||||
elementId: olRecoveryCodesListId
|
||||
});
|
||||
|
||||
insertScriptTags();
|
||||
})();
|
||||
}, [isFetchingTranslations]);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { useEffect } from "react";
|
||||
import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags";
|
||||
import { assert } from "keycloakify/tools/assert";
|
||||
import { KcContext } from "keycloakify/login/KcContext/KcContext";
|
||||
import { waitForElementMountedOnDom } from "keycloakify/tools/waitForElementMountedOnDom";
|
||||
|
||||
type KcContextLike = {
|
||||
url: {
|
||||
@ -59,6 +60,12 @@ export function useScript(params: { authButtonId: string; kcContext: KcContextLi
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await waitForElementMountedOnDom({
|
||||
elementId: authButtonId
|
||||
});
|
||||
|
||||
insertScriptTags();
|
||||
})();
|
||||
}, [isFetchingTranslations]);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { useEffect } from "react";
|
||||
import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags";
|
||||
import { assert } from "keycloakify/tools/assert";
|
||||
import { KcContext } from "keycloakify/login/KcContext/KcContext";
|
||||
import { waitForElementMountedOnDom } from "keycloakify/tools/waitForElementMountedOnDom";
|
||||
|
||||
type KcContextLike = {
|
||||
url: {
|
||||
@ -88,6 +89,12 @@ export function useScript(params: { authButtonId: string; kcContext: KcContextLi
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await waitForElementMountedOnDom({
|
||||
elementId: authButtonId
|
||||
});
|
||||
|
||||
insertScriptTags();
|
||||
})();
|
||||
}, [isFetchingTranslations]);
|
||||
}
|
||||
|
30
src/tools/waitForElementMountedOnDom.ts
Normal file
30
src/tools/waitForElementMountedOnDom.ts
Normal file
@ -0,0 +1,30 @@
|
||||
export async function waitForElementMountedOnDom(params: {
|
||||
elementId: string;
|
||||
}): Promise<void> {
|
||||
const { elementId } = params;
|
||||
|
||||
const getElement = () => document.getElementById(elementId);
|
||||
|
||||
const element = getElement();
|
||||
|
||||
if (element === null) {
|
||||
let prElementPresentInTheDom_resolve: () => void;
|
||||
const prElementPresentInTheDom = new Promise<void>(
|
||||
resolve => (prElementPresentInTheDom_resolve = resolve)
|
||||
);
|
||||
|
||||
// Observe the dom for the element to be added
|
||||
const observer = new MutationObserver(() => {
|
||||
const element = getElement();
|
||||
if (element === null) {
|
||||
return;
|
||||
}
|
||||
observer.disconnect();
|
||||
prElementPresentInTheDom_resolve();
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
await prElementPresentInTheDom;
|
||||
}
|
||||
}
|
@ -16,3 +16,42 @@ type Story = StoryObj<typeof meta>;
|
||||
export const Default: Story = {
|
||||
render: () => <KcPageStory />
|
||||
};
|
||||
export const WithErrorCode: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
code: {
|
||||
success: false,
|
||||
error: "Failed to generate code"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithFrenchLanguage: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
locale: {
|
||||
currentLanguageTag: "fr"
|
||||
},
|
||||
code: {
|
||||
success: true,
|
||||
code: "XYZ789"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithHtmlErrorMessage: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
code: {
|
||||
success: false,
|
||||
error: "Something went wrong. <a href='https://example.com'>Try again</a>"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -16,3 +16,33 @@ type Story = StoryObj<typeof meta>;
|
||||
export const Default: Story = {
|
||||
render: () => <KcPageStory />
|
||||
};
|
||||
export const WithAIAFlow: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
triggered_from_aia: true,
|
||||
url: { loginAction: "/login-action" }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithoutAIAFlow: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
triggered_from_aia: false,
|
||||
url: { loginAction: "/login-action" }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithCustomButtonStyle: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
triggered_from_aia: true,
|
||||
url: { loginAction: "/login-action" }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -16,3 +16,13 @@ type Story = StoryObj<typeof meta>;
|
||||
export const Default: Story = {
|
||||
render: () => <KcPageStory />
|
||||
};
|
||||
export const WithCustomCredentialLabel: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
credentialLabel: "Test Credential",
|
||||
url: { loginAction: "/login-action" }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -26,3 +26,38 @@ export const WithAnotherMessage: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithHtmlErrorMessage: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
message: {
|
||||
summary: "<strong>Error:</strong> Something went wrong. <a href='https://example.com'>Go back</a>"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const FrenchError: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
locale: { currentLanguageTag: "fr" },
|
||||
message: { summary: "Une erreur s'est produite" }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithSkipLink: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
message: { summary: "An error occurred" },
|
||||
skipLink: true,
|
||||
client: {
|
||||
baseUrl: "https://example.com"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -16,3 +16,14 @@ type Story = StoryObj<typeof meta>;
|
||||
export const Default: Story = {
|
||||
render: () => <KcPageStory />
|
||||
};
|
||||
export const WithoutRedirectUrl: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
logout: {
|
||||
clients: []
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -16,3 +16,47 @@ type Story = StoryObj<typeof meta>;
|
||||
export const Default: Story = {
|
||||
render: () => <KcPageStory />
|
||||
};
|
||||
export const WithFormValidationErrors: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
messagesPerField: {
|
||||
existsError: (fieldName: string) => ["email", "firstName"].includes(fieldName),
|
||||
get: (fieldName: string) => {
|
||||
if (fieldName === "email") return "Invalid email format.";
|
||||
if (fieldName === "firstName") return "First name is required.";
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithReadOnlyFields: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
email: { value: "jane.doe@example.com", readOnly: true },
|
||||
firstName: { value: "Jane", readOnly: false }
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithPrefilledFormFields: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
firstName: { value: "Jane" },
|
||||
lastName: { value: "Doe" },
|
||||
email: { value: "jane.doe@example.com" }
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -55,3 +55,42 @@ export const WithRequiredActions: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithPageRedirect: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
message: { summary: "You will be redirected shortly." },
|
||||
pageRedirectUri: "https://example.com"
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithoutClientBaseUrl: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
message: { summary: "No client base URL defined." },
|
||||
client: { baseUrl: undefined }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithMessageHeader: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
messageHeader: "Important Notice",
|
||||
message: { summary: "This is an important message." }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithAdvancedMessage: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
message: { summary: "Please take note of this <strong>important</strong> information." }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -231,3 +231,131 @@ export const WithErrorMessage: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithOneSocialProvider: Story = {
|
||||
render: args => (
|
||||
<KcPageStory
|
||||
{...args}
|
||||
kcContext={{
|
||||
social: {
|
||||
displayInfo: true,
|
||||
providers: [
|
||||
{
|
||||
loginUrl: "google",
|
||||
alias: "google",
|
||||
providerId: "google",
|
||||
displayName: "Google",
|
||||
iconClasses: "fa fa-google"
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithTwoSocialProviders: Story = {
|
||||
render: args => (
|
||||
<KcPageStory
|
||||
{...args}
|
||||
kcContext={{
|
||||
social: {
|
||||
displayInfo: true,
|
||||
providers: [
|
||||
{
|
||||
loginUrl: "google",
|
||||
alias: "google",
|
||||
providerId: "google",
|
||||
displayName: "Google",
|
||||
iconClasses: "fa fa-google"
|
||||
},
|
||||
{
|
||||
loginUrl: "microsoft",
|
||||
alias: "microsoft",
|
||||
providerId: "microsoft",
|
||||
displayName: "Microsoft",
|
||||
iconClasses: "fa fa-windows"
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithNoSocialProviders: Story = {
|
||||
render: args => (
|
||||
<KcPageStory
|
||||
{...args}
|
||||
kcContext={{
|
||||
social: {
|
||||
displayInfo: true,
|
||||
providers: []
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithMoreThanTwoSocialProviders: Story = {
|
||||
render: args => (
|
||||
<KcPageStory
|
||||
{...args}
|
||||
kcContext={{
|
||||
social: {
|
||||
displayInfo: true,
|
||||
providers: [
|
||||
{
|
||||
loginUrl: "google",
|
||||
alias: "google",
|
||||
providerId: "google",
|
||||
displayName: "Google",
|
||||
iconClasses: "fa fa-google"
|
||||
},
|
||||
{
|
||||
loginUrl: "microsoft",
|
||||
alias: "microsoft",
|
||||
providerId: "microsoft",
|
||||
displayName: "Microsoft",
|
||||
iconClasses: "fa fa-windows"
|
||||
},
|
||||
{
|
||||
loginUrl: "facebook",
|
||||
alias: "facebook",
|
||||
providerId: "facebook",
|
||||
displayName: "Facebook",
|
||||
iconClasses: "fa fa-facebook"
|
||||
},
|
||||
{
|
||||
loginUrl: "twitter",
|
||||
alias: "twitter",
|
||||
providerId: "twitter",
|
||||
displayName: "Twitter",
|
||||
iconClasses: "fa fa-twitter"
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithSocialProvidersAndWithoutRememberMe: Story = {
|
||||
render: args => (
|
||||
<KcPageStory
|
||||
{...args}
|
||||
kcContext={{
|
||||
social: {
|
||||
displayInfo: true,
|
||||
providers: [
|
||||
{
|
||||
loginUrl: "google",
|
||||
alias: "google",
|
||||
providerId: "google",
|
||||
displayName: "Google",
|
||||
iconClasses: "fa fa-google"
|
||||
}
|
||||
]
|
||||
},
|
||||
realm: { rememberMe: false }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -41,3 +41,24 @@ export const WithError: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithAppInitiatedAction: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
isAppInitiatedAction: true
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithPreFilledUserLabel: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
totp: {
|
||||
otpCredentials: [{ userLabel: "MyDevice" }]
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -16,3 +16,49 @@ type Story = StoryObj<typeof meta>;
|
||||
export const Default: Story = {
|
||||
render: () => <KcPageStory />
|
||||
};
|
||||
export const WithIdpAlias: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
idpAlias: "Google",
|
||||
brokerContext: {
|
||||
username: "john.doe"
|
||||
},
|
||||
realm: {
|
||||
displayName: "MyRealm"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithoutIdpAlias: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
idpAlias: undefined,
|
||||
brokerContext: {
|
||||
username: "john.doe"
|
||||
},
|
||||
realm: {
|
||||
displayName: "MyRealm"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const WithCustomRealmDisplayName: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
idpAlias: "Facebook",
|
||||
brokerContext: {
|
||||
username: "jane.doe"
|
||||
},
|
||||
realm: {
|
||||
displayName: "CustomRealm"
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -215,3 +215,65 @@ export const WithTermsAcceptance: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithTermsNotAccepted: Story = {
|
||||
render: args => (
|
||||
<KcPageStory
|
||||
{...args}
|
||||
kcContext={{
|
||||
termsAcceptanceRequired: true,
|
||||
messagesPerField: {
|
||||
existsError: (fieldName: string) => fieldName === "termsAccepted",
|
||||
get: (fieldName: string) => (fieldName === "termsAccepted" ? "You must accept the terms." : undefined)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithFieldErrors: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
username: { value: "" },
|
||||
email: { value: "invalid-email" }
|
||||
}
|
||||
},
|
||||
messagesPerField: {
|
||||
existsError: (fieldName: string) => ["username", "email"].includes(fieldName),
|
||||
get: (fieldName: string) => {
|
||||
if (fieldName === "username") return "Username is required.";
|
||||
if (fieldName === "email") return "Invalid email format.";
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithReadOnlyFields: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
username: { value: "johndoe", readOnly: true },
|
||||
email: { value: "jhon.doe@gmail.com", readOnly: false }
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithAutoGeneratedUsername: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
profile: {
|
||||
attributesByName: {
|
||||
username: { value: "autogenerated_username" }
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
@ -45,3 +45,32 @@ export const French: Story = {
|
||||
/>
|
||||
)
|
||||
};
|
||||
export const WithErrorMessage: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
messagesPerField: {
|
||||
existsError: () => true,
|
||||
get: () => "An error occurred while processing your request."
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
||||
export const Spanish: Story = {
|
||||
render: () => (
|
||||
<KcPageStory
|
||||
kcContext={{
|
||||
locale: {
|
||||
currentLanguageTag: "es"
|
||||
},
|
||||
"x-keycloakify": {
|
||||
messages: {
|
||||
termsText: "<p>Mis términos en <strong>Español</strong></p>"
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
|
Reference in New Issue
Block a user