How to Create a Custom Login Theme for Keycloak in Docker
1. Introduction
Keycloak is one of the most popular open-source Identity and Access Management platforms backed by RedHat. It is known for its flexibility where complex enterprise use cases don't fit the available cloud authentication platforms.
For this exercise, we will use the project at https://github.com/czetsuyatech/ct-keycloak-iam, and we should arrive at the following login page.
To do this, we need to familiarise ourselves with the Keycloak theme folder structure to identify the template/CSS files we need to modify.
1.1 Prerequisites
- Prior knowledge of Docker
- Keycloak knowledge (<=v16.1.1)
- Knowledge of FreeMarker (for template customization)
- Docker Desktop
- IntelliJ or any other IDE of your choice
- Understanding of CSS / Flex
- Stable internet connection
2. ct-keycloak-iam Project
- keycloak-docker-assembly
- docker - contains the Dockerfile and compose file
- downloads - copy Keycloak and MySQL JDBC driver here for faster build
- src - contains the keycloak overrides and build tools
- main/resources/themes/czetsuyatech - Keycloak custom theme
- login - custom login page
- docs - usage documentation
2.1 Running Keycloak in a Docker Container
docker-compose -f ./keycloak-docker-assembly/docker/docker-compose-dev.yml up --buildThis will use the Dockerfile inside the docker folder, and the process will run in the following sequence.
- Copy the Keycloak resources into the container, including the default realm, MySQL module, theme, providers, and cli & batch scripts.
- Download the Keycloak server and MySQL driver if they don't exist in the downloads folder.
- Extract the Keycloak server.
- Install the following
- Theme
- MySQL module and driver
- Custom providers
- Custom realm
- Admin - http://localhost:8080, keycloak.admin/keycloak.admin
- Create a user that we can use to log in later.
- User login - http://localhost:8080/auth/realms/czetsuyatech/account
3. Custom Keycloak Theme
- base - basic HTML, almost no styles
- keycloak - Keycloak brand,
- keycloak.v2 - an extension of #2
- login
- theme.properties - it contains information about this particular part of the theme, what is its base, the styles, scripts, locale, etc.
- template.ftl - base template for the login pages like sign in, signup, forgot password, OTP, verify email, etc.
- login.ftl - specific page for login
- resources
- CSS - styles
- img - images
- messages - language/translations/localizations
- messages_en.properties
- Divide the page into two columns.
- Show a logo on the left side (we can add some background images here).
- Show a login subtitle (under the Sign in label).
3.1 Here are the CSS tags necessary for the first goal:
- login-pf-page - the parent component
- login-pf-page-header - left component
- card-pf - right component
.login-pf-page { padding: 50px; display: flex; justify-content: center; align-items: stretch; height: 100%; } .login-pf-page-header { height: 100%; flex: 0 0 35em; display: flex; flex-direction: column; justify-content: space-around; border-top-left-radius: 50px; border-bottom-left-radius: 50px; background-color: #36383a; } .card-pf { border-top: 0; margin: 0; flex: 0 0 35em; display: flex; flex-direction: column; justify-content: center; border-top-right-radius: 50px; border-bottom-right-radius: 50px; }
3.2 Show a logo on the left side.
<div class="logo"> <img alt="Czetsuya Tech" src="${url.resourcesPath}/img/ct-logo.svg" width="120"/> </div>
3.3 Add a sub-title.
<div class="login-subtitle" data-qa-id="login-subtitle">${msg("signinIntro")}Finally, here are the override files:
Post a Comment