kcContextExclusionsFtl
Keycloakify shifts page generation from the backend to the client. To achieve this, Keycloakify creates a global kcContext object, which holds the necessary information for generating HTML pages.
This object contains no sensitive data—only the information that the Keycloak team considers essential for rendering the various login pages. Additionally, if you have custom plugins, such as keycloak-email-whitelisting, they may introduce additional values into this object.

If you'd like to prevent some values of the FreeMarker context from being forwarded to the client you can do it with the kcContextExclusionsFtl option.
Let's say in this example that we would like to exclude:
kcContext.keycloakifyVersionkcContext.realm.actionTokenGeneratedByUserLifespanMinutesin the register.ftl pagekcContext.realm.idpVerifyAccountLinkActionTokenLifespanMinutesin the register.ftl page
This is how you would do it:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { keycloakify } from "keycloakify/vite-plugin";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
keycloakify({
// ...
kcContextExclusionsFtl: `
<#if (
key == "keycloakifyVersion" &&
areSamePath(path, [])
)>
<#continue>
</#if>
<#if (
xKeycloakify.pageId == "register.ftl" &&
[
"actionTokenGeneratedByUserLifespanMinutes",
"idpVerifyAccountLinkActionTokenLifespanMinutes"
]?seq_contains(key) &&
areSamePath(path, ["realm"]
)>
<#continue>
</#if>
`
})
]
});<#if (
key == "keycloakifyVersion" &&
areSamePath(path, [])
)>
<#continue>
</#if>
<#if (
xKeycloakify.pageId == "register.ftl" &&
[
"actionTokenGeneratedByUserLifespanMinutes",
"idpVerifyAccountLinkActionTokenLifespanMinutes"
]?seq_contains(key) &&
areSamePath(path, ["realm"]
)>
<#continue>
</#if>{
"keycloakify": {
// ...
"kcContextExclusionsFtl": "./kcContextExclusions.ftl"
}
}The code that you provide will be injected here.
For more detailed example you can refer to this section of the code that defines the the default exclusions:
More advanced modification of the kcContext
If you feel limited by this option you can take ownership of the FreeMarker template that generates the kcContext. Do do this using the wonderfull patch-package.
yarn add --dev patch-packageAnd edit the FreeMarker template that generates the KcContext in:
node_modules/keycloakify/src/bin/keycloakify/generateFtl/kcContextDeclarationTemplate.ftl
You can then create a diff for your changes by running:
npx patch-package keycloakifyThen add a postinstall script to your package.json:
{
"name": "keycloakify-starter",
"scripts": {
"postinstall": "patch-package",
"dev": "vite",Last updated
Was this helpful?