This is the documentation for v6, checkout the latest version
Keycloakify
HomeGitHubStartersStorybookDiscordKeycloak-js Alternative
v5
  • Keycloakify
  • Release Notes & Upgrade Instructions
  • FAQ
v5
  • 🏁Requirements
  • πŸ‘¨β€πŸ’»πŸ‘¨πŸ’» Quick start
  • πŸ§ͺDevelopment
  • πŸ“§Email customization
  • βœ’οΈTerms and conditions
  • βœ…Realtime input validation
  • ⚠️Limitations
  • πŸŒ‰Context persistence
  • 🌐Adding i18n messages keys
  • ⚑Performance optimization
  • πŸ’‚Email domain acceptlist
  • πŸ›‘Keycloak error in log
  • πŸ’ŸContributing
Powered by GitBook
On this page

Was this helpful?

πŸ‘¨πŸ’» Quick start

PreviousRequirementsNextDevelopment

Last updated 27 days ago

Was this helpful?

It's a good idea to first read this quick start section to understand the basic of how Keycloakify works.

However, we recommend you start hacking from instead of setting up Keycloakify from scratch.

Save yourself some time, have quick look at the . Windows users in particular!

yarn add keycloakify @emotion/react

"scripts": {
    "keycloak": "yarn build && build-keycloak-theme",
}
yarn keycloak # generates the keycloak-theme.jar

On the console will be printed all the instructions about how to load the generated theme in Keycloak

The first approach is to only customize the style of the default Keycloak login theme by providing your own class names.

src/index.tsx

import { KcApp, defaultKcProps, getKcContext } from "keycloakify";
//We assume the file contains: ".my-class { color: red; }"
import "./index.css";

const { kcContext } = getKcContext();

if( kcContex === undefined ){
    throw new Error(
        "This app is a Keycloak theme" +
        "It isn't meant to be deployed outside of Keycloak"
    );
}

reactDom.render(
    <KcApp
        kcContext={kcContext}
        {...{
            ...defaultKcProps,
            "kcHeaderWrapperClass": "my-class",
        }}
    />,
    document.getElementById("root"),
);

The above snippet of code assumes you are in a react project wich only purpose is to be a Keycloak theme.

But if you want to make your keycloak theme an integral part of a preexisting React app you would apply the following modification to the above snipet:

+import {Β App }Β from "<you know where";
 import { KcApp, defaultKcProps, getKcContext } from "keycloakify";
 import "./index.css";

 const { kcContext } = getKcContext();

-if( kcContex === undefined ){
-    throw new Error(
-        "This app is a Keycloak theme" +
-        "It isn't meant to be deployed outside of Keycloak"
-    );
-}

 reactDom.render(
+    kcContext === undefined ?
+        <App /> :
         <KcApp
             kcContext={kcContext}
             {...{
                 ...defaultKcProps,
                 "kcHeaderWrapperClass": myClassName,
             }}
         />,
     document.getElementById("root"),
);

Real world example

To give you an idea of what you can already achieve by only customizing the style the style,

The keycloakify components are a plain React translation of the default theme that comes with Keycloak v11.0.3.

You can download the FTL/CSS source files the components are based on with the following command:

npx -p keycloakify download-builtin-keycloak-theme

If you want to go beyond only customizing the CSS you can re-implement some of the pages or even add new ones.

How to import the theme in Keycloak

Specific instruction on how to proceed will be printed in the console with yarn keycloak.

Result: MYREALM is red

Here is that produces:

Results obtained with CSS only customization of the default theme

then select version 11.0.3 ().

If you want to go this way checkout the demo setup provided . If you prefer a real life example you can checkout . The web app is in production .

See also for more info on how to add support for extra ftl pages.

πŸ‘¨β€πŸ’»
the demo setup
requirements page
package.json
the code
Video demo
here
onyxia-web's source
here
this documentation section