Skip to content

Commit

Permalink
Custom Keycloak theme with required login (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich authored Nov 21, 2024
1 parent f95852c commit e12cf93
Show file tree
Hide file tree
Showing 55 changed files with 23,119 additions and 2,393 deletions.
27 changes: 27 additions & 0 deletions keycloakify/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:storybook/recommended"
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-redeclare": "off",
"no-labels": "off"
},
overrides: [
{
files: ["**/*.stories.*"],
rules: {
"import/no-anonymous-default-export": "off"
}
}
]
};
56 changes: 56 additions & 0 deletions keycloakify/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# yarn cache directory
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions


# Optional REPL history
.node_repl_history

.vscode

.DS_Store

/dist

/build
/storybook-static
6 changes: 6 additions & 0 deletions keycloakify/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
/dist/
/dist_keycloak/
/public/keycloakify-dev-resources/
/.vscode/
/.yarn_home/
25 changes: 25 additions & 0 deletions keycloakify/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"printWidth": 90,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "avoid",
"overrides": [
{
"files": [
"**/login/pages/*.tsx",
"**/account/pages/*.tsx",
"**/login/Template.tsx",
"**/account/Template.tsx",
"**/login/UserProfileFormFields.tsx",
"KcApp.tsx"
],
"options": {
"printWidth": 150
}
}
]
}
12 changes: 12 additions & 0 deletions keycloakify/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [],
framework: {
name: "@storybook/react-vite",
options: {}
},
staticDirs: ["../public"]
};
export default config;
25 changes: 25 additions & 0 deletions keycloakify/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<style>
body.sb-show-main.sb-main-padded {
padding: 0;
}

/* Following styles are just meant to avoid white flash when switching from one story to another */
@keyframes fadeToTransparent {
from {
background-color: #393939;
}

to {
background-color: transparent;
}
}
html {
animation: fadeToTransparent 500ms forwards ease-in;
}
body > .sb-preparing-docs {
visibility: hidden;
}
body > .sb-preparing-story {
visibility: hidden;
}
</style>
14 changes: 14 additions & 0 deletions keycloakify/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i
}
}
}
};

export default preview;
21 changes: 21 additions & 0 deletions keycloakify/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 GitHub user u/garronej

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions keycloakify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<p align="center">
<i>🚀 <a href="https://keycloakify.dev">Keycloakify</a> v11 starter 🚀</i>
<br/>
<br/>
</p>

This starter is based on Vite. There is also [a Webpack based starter](https://github.com/keycloakify/keycloakify-starter-webpack).

# Quick start

```bash
git clone https://github.com/keycloakify/keycloakify-starter
cd keycloakify-starter
yarn install # Or use an other package manager, just be sure to delete the yarn.lock if you use another package manager.
```

# Testing the theme locally

[Documentation](https://docs.keycloakify.dev/v/v10/testing-your-theme)

# How to customize the theme

[Documentation](https://docs.keycloakify.dev/v/v10/customization-strategies)

# Building the theme

You need to have [Maven](https://maven.apache.org/) installed to build the theme (Maven >= 3.1.1, Java >= 7).
The `mvn` command must be in the $PATH.

- On macOS: `brew install maven`
- On Debian/Ubuntu: `sudo apt-get install maven`
- On Windows: `choco install openjdk` and `choco install maven` (Or download from [here](https://maven.apache.org/download.cgi))

```bash
npm run build-keycloak-theme
```

Note that by default Keycloakify generates multiple .jar files for different versions of Keycloak.
You can customize this behavior, see documentation [here](https://docs.keycloakify.dev/targeting-specific-keycloak-versions).

# Initializing the account theme

```bash
npx keycloakify initialize-account-theme
```

# Initializing the email theme

```bash
npx keycloakify initialize-email-theme
```

# GitHub Actions

The starter comes with a generic GitHub Actions workflow that builds the theme and publishes
the jars [as GitHub releases artifacts](https://github.com/keycloakify/keycloakify-starter/releases/tag/v10.0.0).
To release a new version **just update the `package.json` version and push**.

To enable the workflow go to your fork of this repository on GitHub then navigate to:
`Settings` > `Actions` > `Workflow permissions`, select `Read and write permissions`.
21 changes: 21 additions & 0 deletions keycloakify/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/login/index.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}
Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions keycloakify/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="theme-color" content="default-color" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
</head>

<script>
// JavaScript should be placed inside <script> tags and not as FreeMarker expressions
const theme = localStorage.getItem("theme");
const browserDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
if (theme !== null) {
if (theme === "dark") {
document.documentElement.classList.add("dark");
}
document.documentElement.setAttribute("data-color-mode", theme);
} else {
if (browserDark) {
document.documentElement.classList.add("dark");
}
document.documentElement.setAttribute(
"data-color-mode",
browserDark ? "dark" : "light"
);
localStorage.setItem("theme", browserDark ? "dark" : "light");
}

const metaThemeColor = document.querySelector('meta[name="theme-color"]');
if (metaThemeColor) {
metaThemeColor.setAttribute(
"content",
"hsl(" +
getComputedStyle(document.documentElement).getPropertyValue(
"--background"
) +
")"
);
}
</script>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit e12cf93

Please sign in to comment.