Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
81279a5cc5 | |||
59f0a843b0 | |||
c094f70171 | |||
0858fe6319 | |||
5012ec0ccc | |||
990a24fab2 | |||
036b6bf82a | |||
8272a02b52 | |||
e346b1d9d2 | |||
2309bd21c6 | |||
7d6476c1b5 | |||
e892a0e7e6 | |||
ca5b41e730 | |||
9b18234112 | |||
5274368f47 | |||
1415c24028 | |||
4a084f5859 | |||
a30c9eb0cd | |||
85d3b40b8e | |||
335afec230 | |||
69fa49848a | |||
7a09051127 | |||
07ee0ecb8b | |||
6f133428f8 | |||
4f733736db | |||
d96ff13a67 | |||
2c1351ce47 | |||
96cd56ec77 | |||
e5b2096d65 | |||
3aa140335f | |||
4cafaa2492 | |||
9c633a7521 | |||
e27845ba91 | |||
2a8708a45b | |||
6874fa4c24 | |||
ba531a4927 | |||
20175b57cf | |||
ad275e4c34 | |||
060b9fe0de | |||
17b24d14ed | |||
2d278b0680 | |||
fb5975e4f1 | |||
24fccaf513 | |||
293953aa1b | |||
1049e312f9 | |||
a2db250600 | |||
cf7fe8c337 | |||
f5350097bf | |||
1cb5dd461b | |||
845599a5e8 | |||
0cc02c292f | |||
1919702326 |
60
CHANGELOG.md
60
CHANGELOG.md
@ -1,3 +1,63 @@
|
|||||||
|
### **0.3.18** (2021-04-01)
|
||||||
|
|
||||||
|
- Fix error.ftt, Adopt best effort strategy to convert ftl values into JS
|
||||||
|
|
||||||
|
### **0.3.17** (2021-03-29)
|
||||||
|
|
||||||
|
- Use push instead of replace in keycloak-js adapter to enable going back
|
||||||
|
|
||||||
|
### **0.3.15** (2021-03-28)
|
||||||
|
|
||||||
|
- Remove all reference to --external-assets, broken feature
|
||||||
|
|
||||||
|
### **0.3.14** (2021-03-28)
|
||||||
|
|
||||||
|
- Fix standalone mode: imports from js
|
||||||
|
|
||||||
|
### **0.3.13** (2021-03-26)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### **0.3.12** (2021-03-26)
|
||||||
|
|
||||||
|
- Fix mocksContext
|
||||||
|
|
||||||
|
### **0.3.11** (2021-03-26)
|
||||||
|
|
||||||
|
- Fix previous build, improve README
|
||||||
|
|
||||||
|
### **0.3.10** (2021-03-26)
|
||||||
|
|
||||||
|
- Handle <style> tag, improve documentation
|
||||||
|
|
||||||
|
### **0.3.9** (2021-03-25)
|
||||||
|
|
||||||
|
- Update readme
|
||||||
|
- Document --external-assets
|
||||||
|
- Update README.md
|
||||||
|
- Update README.md
|
||||||
|
- Update README.md
|
||||||
|
|
||||||
|
### **0.3.8** (2021-03-22)
|
||||||
|
|
||||||
|
- Make standalone mode the default
|
||||||
|
|
||||||
|
### **0.3.7** (2021-03-22)
|
||||||
|
|
||||||
|
- (test) external asset mode by default
|
||||||
|
|
||||||
|
### **0.3.6** (2021-03-22)
|
||||||
|
|
||||||
|
- Fix previous release
|
||||||
|
|
||||||
|
### **0.3.5** (2021-03-22)
|
||||||
|
|
||||||
|
- support homepage with urlPath
|
||||||
|
|
||||||
|
### **0.3.4** (2021-03-22)
|
||||||
|
|
||||||
|
- Bugfix: Import assets from CSS
|
||||||
|
|
||||||
### **0.3.3** (2021-03-22)
|
### **0.3.3** (2021-03-22)
|
||||||
|
|
||||||
- Fix submit not receving correct text
|
- Fix submit not receving correct text
|
||||||
|
99
README.md
99
README.md
@ -20,8 +20,10 @@
|
|||||||
|
|
||||||
The problem:
|
The problem:
|
||||||
|
|
||||||

|
<p align="center">
|
||||||
|
<i>Without keycloakify:</i><br>
|
||||||
|
<img src="https://user-images.githubusercontent.com/6702424/108838381-dbbbcf80-75d3-11eb-8ae8-db41563ef9db.gif">
|
||||||
|
</p>
|
||||||
When we redirected to Keycloak the user suffers from a harsh context switch.
|
When we redirected to Keycloak the user suffers from a harsh context switch.
|
||||||
Keycloak does offer a way to customize theses pages but it requires a lot of raw HTML/CSS hacking
|
Keycloak does offer a way to customize theses pages but it requires a lot of raw HTML/CSS hacking
|
||||||
to reproduce the look and feel of a specific app. Not mentioning the maintenance cost of such an endeavour.
|
to reproduce the look and feel of a specific app. Not mentioning the maintenance cost of such an endeavour.
|
||||||
@ -29,14 +31,12 @@ to reproduce the look and feel of a specific app. Not mentioning the maintenance
|
|||||||
Wouldn't it be great if we could just design the login and register pages as if they where part of our app?
|
Wouldn't it be great if we could just design the login and register pages as if they where part of our app?
|
||||||
Here is `yarn add keycloakify` for you 🍸
|
Here is `yarn add keycloakify` for you 🍸
|
||||||
|
|
||||||
TODO: Insert video after.
|
<p align="center">
|
||||||
|
<i>With keycloakify:</i><br>
|
||||||
|
<img src="https://github.com/InseeFrLab/keycloakify/releases/download/v0.3.8/keycloakify_after.gif">
|
||||||
|
</p>
|
||||||
|
|
||||||
Tested with the following Keycloak versions:
|
**TL;DR**: [Here](https://github.com/garronej/keycloakify-demo-app) is a Hello World React project with Keycloakify set up.
|
||||||
- [11.0.3](https://hub.docker.com/layers/jboss/keycloak/11.0.3/images/sha256-4438f1e51c1369371cb807dffa526e1208086b3ebb9cab009830a178de949782?context=explore)
|
|
||||||
- [12.0.4](https://hub.docker.com/layers/jboss/keycloak/12.0.4/images/sha256-67e0c88e69bd0c7aef972c40bdeb558a974013a28b3668ca790ed63a04d70584?context=explore)
|
|
||||||
|
|
||||||
**Disclaimer**: This tool will be maintained to stay compatible with Keycloak v11 and up, however, the default pages you will get
|
|
||||||
(before you customize it) will always be the ones of the Keycloak v11.
|
|
||||||
|
|
||||||
- [Motivations](#motivations)
|
- [Motivations](#motivations)
|
||||||
- [How to use](#how-to-use)
|
- [How to use](#how-to-use)
|
||||||
@ -46,37 +46,47 @@ Tested with the following Keycloak versions:
|
|||||||
- [Changing the look **and** feel](#changing-the-look-and-feel)
|
- [Changing the look **and** feel](#changing-the-look-and-feel)
|
||||||
- [Hot reload](#hot-reload)
|
- [Hot reload](#hot-reload)
|
||||||
- [GitHub Actions](#github-actions)
|
- [GitHub Actions](#github-actions)
|
||||||
- [REQUIREMENTS](#requirements)
|
- [Requirements](#requirements)
|
||||||
|
- [Limitations](#limitations)
|
||||||
|
- [`process.env.PUBLIC_URL` not supported.](#processenvpublic_url-not-supported)
|
||||||
|
- [`@font-face` importing fonts from the `src/` dir](#font-face-importing-fonts-from-thesrc-dir)
|
||||||
|
- [Example of setup that **won't** work](#example-of-setup-that-wont-work)
|
||||||
|
- [Workarounds](#workarounds)
|
||||||
|
- [Implement context persistence (optional)](#implement-context-persistence-optional)
|
||||||
- [API Reference](#api-reference)
|
- [API Reference](#api-reference)
|
||||||
- [The build tool](#the-build-tool)
|
- [The build tool](#the-build-tool)
|
||||||
- [Implement context persistance (optional)](#implement-context-persistance-optional)
|
|
||||||
|
|
||||||
# How to use
|
# How to use
|
||||||
## Setting up the build tool
|
## Setting up the build tool
|
||||||
|
|
||||||
Add `keycloakify` to the dev dependencies of your project `npm install --save-dev keycloakify` or `yarn add --dev keycloakify`
|
[`package.json`](https://github.com/garronej/keycloakify-demo-app/blob/main/package.json)
|
||||||
then configure your `package.json` build's script to build the keycloak's theme by adding `&& build-keycloak-theme`.
|
|
||||||
|
|
||||||
Typically you will get:
|
|
||||||
|
|
||||||
`package.json`
|
|
||||||
```json
|
```json
|
||||||
"devDependencies": {
|
"homepage": "https://URL.OF/YOUR-APP"
|
||||||
|
"dependencies": {
|
||||||
"keycloakify": "^0.0.10"
|
"keycloakify": "^0.0.10"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"keycloak": "yarn build && build-keycloak-theme",
|
"keycloak": "yarn build && build-keycloak-theme",
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
`"homepage"` must be specified only if the url path is not `/`
|
||||||
|
(Onl `/YOUR-APP` matters `URL.OF` don't have to be the actual domain)
|
||||||
|
|
||||||
Then run `yarn keycloak` or `npm run keycloak`, you will be provided with instructions
|
It is mandatory that you specify the url where your app will be available
|
||||||
about how to load the theme into Keycloak.
|
using the `homepage` field.
|
||||||
|
|
||||||
|
Once you've edited your `package.json` you can install your new
|
||||||
|
dependency with `yarn install` and build the keycloak theme with
|
||||||
|
`yarn keycloak`.
|
||||||
|
|
||||||
|
Once the build is complete instructions about how to load
|
||||||
|
the theme into Keycloak are printed in the console.
|
||||||
|
|
||||||
## Developing your login and register pages in your React app
|
## Developing your login and register pages in your React app
|
||||||
|
|
||||||
### Just changing the look
|
### Just changing the look
|
||||||
|
|
||||||
The fist approach is to only arr/replace the default class names by your
|
The first approach is to only arr/replace the default class names by your
|
||||||
own.
|
own.
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
@ -159,30 +169,50 @@ Checkout [this concrete example](https://github.com/garronej/keycloakify-demo-ap
|
|||||||
[Here is a demo repo](https://github.com/garronej/keycloakify-demo-app) to show how to automate
|
[Here is a demo repo](https://github.com/garronej/keycloakify-demo-app) to show how to automate
|
||||||
the building and publishing of the theme (the .jar file).
|
the building and publishing of the theme (the .jar file).
|
||||||
|
|
||||||
# REQUIREMENTS
|
# Requirements
|
||||||
|
|
||||||
|
Tested with the following Keycloak versions:
|
||||||
|
- [11.0.3](https://hub.docker.com/layers/jboss/keycloak/11.0.3/images/sha256-4438f1e51c1369371cb807dffa526e1208086b3ebb9cab009830a178de949782?context=explore)
|
||||||
|
- [12.0.4](https://hub.docker.com/layers/jboss/keycloak/12.0.4/images/sha256-67e0c88e69bd0c7aef972c40bdeb558a974013a28b3668ca790ed63a04d70584?context=explore)
|
||||||
|
|
||||||
|
This tool will be maintained to stay compatible with Keycloak v11 and up, however, the default pages you will get
|
||||||
|
(before you customize it) will always be the ones of the Keycloak v11.
|
||||||
|
|
||||||
This tools assumes you are bundling your app with Webpack (tested with 4.44.2) .
|
This tools assumes you are bundling your app with Webpack (tested with 4.44.2) .
|
||||||
It assumes there is a `build/` directory at the root of your react project directory containing a `index.html` file
|
It assumes there is a `build/` directory at the root of your react project directory containing a `index.html` file
|
||||||
and a `static/` directory generated by webpack.
|
and a `build/static/` directory generated by webpack.
|
||||||
|
|
||||||
**All this is defaults with [`create-react-app`](https://create-react-app.dev)** (tested with 4.0.3=)
|
**All this is defaults with [`create-react-app`](https://create-react-app.dev)** (tested with 4.0.3=)
|
||||||
|
|
||||||
- For building the theme: `mvn` (Maven) must be installed
|
- For building the theme: `mvn` (Maven) must be installed
|
||||||
- For development, (testing the theme in a local container ): `rm`, `mkdir`, `wget`, `unzip` are assumed to be available
|
- For development (testing the theme in a local container ): `rm`, `mkdir`, `wget`, `unzip` are assumed to be available
|
||||||
and `docker` up and running.
|
and `docker` up and running.
|
||||||
|
|
||||||
NOTE: This build tool has only be tested on MacOS.
|
NOTE: This build tool has only be tested on MacOS.
|
||||||
|
|
||||||
# API Reference
|
# Limitations
|
||||||
|
|
||||||
## The build tool
|
## `process.env.PUBLIC_URL` not supported.
|
||||||
|
|
||||||
Part of the lib that runs with node, at build time.
|
You won't be able to [import things from your public directory in your JavaScript code](https://create-react-app.dev/docs/using-the-public-folder/#adding-assets-outside-of-the-module-system). (This isn't recommended anyway).
|
||||||
|
|
||||||
- `npx build-keycloak-theme`: Builds the theme, the CWD is assumed to be the root of your react project.
|
## `@font-face` importing fonts from the `src/` dir
|
||||||
- `npx download-sample-keycloak-themes`: Downloads the keycloak default themes (for development purposes)
|
### Example of setup that **won't** work
|
||||||
|
|
||||||
# Implement context persistance (optional)
|
- We have a `fonts/` directory in `src/`
|
||||||
|
- We import the font like this [`src: url("/fonts/my-font.woff2") format("woff2");`(https://github.com/garronej/keycloakify-demo-app/blob/07d54a3012ef354ee12b1374c6f7ad1cb125d56b/src/fonts.scss#L4) in a `.scss` a file.
|
||||||
|
|
||||||
|
### Workarounds
|
||||||
|
|
||||||
|
If it is possible, use Google Fonts or any other font provider.
|
||||||
|
|
||||||
|
If you want to host your font recommended approach is to move your fonts into the `public`
|
||||||
|
directory and to place your `@font-face` statements in the `public/index.html`.
|
||||||
|
Example [here]().
|
||||||
|
|
||||||
|
You can also [use your explicit url](https://github.com/garronej/keycloakify-demo-app/blob/2de8a9eb6f5de9c94f9cd3991faad0377e63268c/src/fonts.scss#L16) but don't forget [`Access-Control-Allow-Origin`](https://github.com/garronej/keycloakify-demo-app/blob/2de8a9eb6f5de9c94f9cd3991faad0377e63268c/nginx.conf#L17-L19).
|
||||||
|
|
||||||
|
# Implement context persistence (optional)
|
||||||
|
|
||||||
If, before logging in, a user has selected a specific language
|
If, before logging in, a user has selected a specific language
|
||||||
you don't want it to be reset to default when the user gets redirected to
|
you don't want it to be reset to default when the user gets redirected to
|
||||||
@ -240,3 +270,12 @@ keycloakInstance.init({
|
|||||||
If you really want to go the extra miles and avoid having the white
|
If you really want to go the extra miles and avoid having the white
|
||||||
flash of the blank html before the js bundle have been evaluated
|
flash of the blank html before the js bundle have been evaluated
|
||||||
[here is a snippet](https://github.com/InseeFrLab/onyxia-ui/blob/a77eb502870cfe6878edd0d956c646d28746d053/public/index.html#L5-L54) that you can place in your `public/index.html` if you are using `powerhooks/useGlobalState`.
|
[here is a snippet](https://github.com/InseeFrLab/onyxia-ui/blob/a77eb502870cfe6878edd0d956c646d28746d053/public/index.html#L5-L54) that you can place in your `public/index.html` if you are using `powerhooks/useGlobalState`.
|
||||||
|
|
||||||
|
# API Reference
|
||||||
|
|
||||||
|
## The build tool
|
||||||
|
|
||||||
|
Part of the lib that runs with node, at build time.
|
||||||
|
|
||||||
|
- `npx build-keycloak-theme`: Builds the theme, the CWD is assumed to be the root of your react project.
|
||||||
|
- `npx download-sample-keycloak-themes`: Downloads the keycloak default themes (for development purposes)
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "0.3.3",
|
"version": "0.3.18",
|
||||||
"description": "Keycloak theme generator for Reacts app",
|
"description": "Keycloak theme generator for Reacts app",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -14,8 +14,7 @@
|
|||||||
"grant-exec-perms": "node dist/bin/tools/grant-exec-perms.js",
|
"grant-exec-perms": "node dist/bin/tools/grant-exec-perms.js",
|
||||||
"test": "node dist/test",
|
"test": "node dist/test",
|
||||||
"copy-files": "copyfiles -u 1 src/**/*.ftl src/**/*.xml src/**/*.js dist/",
|
"copy-files": "copyfiles -u 1 src/**/*.ftl src/**/*.xml src/**/*.js dist/",
|
||||||
"generate-messages": "node dist/bin/generate-i18n-messages.js",
|
"generate-messages": "node dist/bin/generate-i18n-messages.js"
|
||||||
"watch": "tsc -w"
|
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"build-keycloak-theme": "dist/bin/build-keycloak-theme/index.js",
|
"build-keycloak-theme": "dist/bin/build-keycloak-theme/index.js",
|
||||||
|
112
src/bin/build-keycloak-theme/generateFtl/common.ftl
Normal file
112
src/bin/build-keycloak-theme/generateFtl/common.ftl
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<script>const _=
|
||||||
|
{
|
||||||
|
"url": (function (){
|
||||||
|
|
||||||
|
<#if !url?has_content>
|
||||||
|
return undefined;
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
return {
|
||||||
|
"loginAction": "${(url.loginAction!'')?no_esc}",
|
||||||
|
"resourcesPath": "${(url.resourcesPath!'')?no_esc}",
|
||||||
|
"resourcesCommonPath": "${(url.resourcesCommonPath!'')?no_esc}",
|
||||||
|
"loginRestartFlowUrl": "${(url.loginRestartFlowUrl!'')?no_esc}",
|
||||||
|
"loginUrl": "${(url.loginUrl!'')?no_esc}"
|
||||||
|
};
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"realm": {
|
||||||
|
"displayName": "${realm.displayName!''}" || undefined,
|
||||||
|
"displayNameHtml": "${realm.displayNameHtml!''}" || undefined,
|
||||||
|
"internationalizationEnabled": ${(realm.internationalizationEnabled!false)?c},
|
||||||
|
"registrationEmailAsUsername": ${(realm.registrationEmailAsUsername!false)?c},
|
||||||
|
},
|
||||||
|
"locale": (function (){
|
||||||
|
|
||||||
|
<#if !realm.internationalizationEnabled>
|
||||||
|
return undefined;
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
return {
|
||||||
|
"supported": (function(){
|
||||||
|
|
||||||
|
<#if !realm.internationalizationEnabled>
|
||||||
|
return undefined;
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
var out= [];
|
||||||
|
|
||||||
|
<#list locale.supported as lng>
|
||||||
|
out.push({
|
||||||
|
"url": "${lng.url?no_esc}",
|
||||||
|
"label": "${lng.label}",
|
||||||
|
"languageTag": "${lng.languageTag}"
|
||||||
|
});
|
||||||
|
</#list>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"current": "${locale.current}"
|
||||||
|
};
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"auth": (function (){
|
||||||
|
|
||||||
|
<#if !auth?has_content>
|
||||||
|
return undefined;
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
var out= {
|
||||||
|
"showUsername": ${auth.showUsername()?c},
|
||||||
|
"showResetCredentials": ${auth.showResetCredentials()?c},
|
||||||
|
"showTryAnotherWayLink": ${auth.showTryAnotherWayLink()?c},
|
||||||
|
};
|
||||||
|
|
||||||
|
<#if auth.showUsername() && !auth.showResetCredentials()>
|
||||||
|
Object.assign(
|
||||||
|
out,
|
||||||
|
{
|
||||||
|
"attemptedUsername": "${auth.attemptedUsername}"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"scripts": (function(){
|
||||||
|
|
||||||
|
var out = [];
|
||||||
|
|
||||||
|
<#if scripts??>
|
||||||
|
<#list scripts as script>
|
||||||
|
out.push("${script}");
|
||||||
|
</#list>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"message": (function (){
|
||||||
|
|
||||||
|
<#if !message?has_content>
|
||||||
|
return undefined;
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
return {
|
||||||
|
"type": "${message.type}",
|
||||||
|
"summary": String.htmlUnescape("${message.summary}")
|
||||||
|
};
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"isAppInitiatedAction": (function (){
|
||||||
|
|
||||||
|
<#if isAppInitiatedAction??>
|
||||||
|
return true;
|
||||||
|
</#if>
|
||||||
|
return false;
|
||||||
|
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
</script>
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
import cheerio from "cheerio";
|
import cheerio from "cheerio";
|
||||||
import {
|
import {
|
||||||
replaceImportFromStaticInJsCode,
|
replaceImportsFromStaticInJsCode,
|
||||||
|
replaceImportsInInlineCssCode,
|
||||||
generateCssCodeToDefineGlobals
|
generateCssCodeToDefineGlobals
|
||||||
} from "../replaceImportFromStatic";
|
} from "../replaceImportFromStatic";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@ -18,7 +19,7 @@ function loadAdjacentFile(fileBasename: string){
|
|||||||
.toString("utf8");
|
.toString("utf8");
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadFtlFile(ftlFileBasename: PageId | "template.ftl") {
|
function loadFtlFile(ftlFileBasename: PageId | "common.ftl") {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return loadAdjacentFile(ftlFileBasename)
|
return loadAdjacentFile(ftlFileBasename)
|
||||||
@ -29,21 +30,23 @@ function loadFtlFile(ftlFileBasename: PageId | "template.ftl") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function generateFtlFilesCodeFactory(
|
export function generateFtlFilesCodeFactory(
|
||||||
params: {
|
params: {
|
||||||
ftlValuesGlobalName: string;
|
ftlValuesGlobalName: string;
|
||||||
cssGlobalsToDefine: Record<string, string>;
|
cssGlobalsToDefine: Record<string, string>;
|
||||||
indexHtmlCode: string;
|
indexHtmlCode: string;
|
||||||
|
urlPathname: string;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const { ftlValuesGlobalName, cssGlobalsToDefine, indexHtmlCode } = params;
|
const { ftlValuesGlobalName, cssGlobalsToDefine, indexHtmlCode, urlPathname } = params;
|
||||||
|
|
||||||
const $ = cheerio.load(indexHtmlCode);
|
const $ = cheerio.load(indexHtmlCode);
|
||||||
|
|
||||||
$("script:not([src])").each((...[, element]) => {
|
$("script:not([src])").each((...[, element]) => {
|
||||||
|
|
||||||
const { fixedJsCode } = replaceImportFromStaticInJsCode({
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
||||||
ftlValuesGlobalName,
|
ftlValuesGlobalName,
|
||||||
"jsCode": $(element).html()!
|
"jsCode": $(element).html()!
|
||||||
});
|
});
|
||||||
@ -52,6 +55,17 @@ export function generateFtlFilesCodeFactory(
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("style").each((...[, element]) => {
|
||||||
|
|
||||||
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||||
|
"cssCode": $(element).html()!,
|
||||||
|
"urlPathname": params.urlPathname
|
||||||
|
});
|
||||||
|
|
||||||
|
$(element).text(fixedCssCode);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
([
|
([
|
||||||
["link", "href"],
|
["link", "href"],
|
||||||
["script", "src"],
|
["script", "src"],
|
||||||
@ -60,18 +74,24 @@ export function generateFtlFilesCodeFactory(
|
|||||||
|
|
||||||
const href = $(element).attr(attrName);
|
const href = $(element).attr(attrName);
|
||||||
|
|
||||||
if (!href?.startsWith("/")) {
|
if (href === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(element).attr(attrName, "${url.resourcesPath}/build" + href);
|
$(element).attr(
|
||||||
|
attrName,
|
||||||
|
href.replace(
|
||||||
|
new RegExp(`^${urlPathname.replace(/\//g, "\\/")}`),
|
||||||
|
"${url.resourcesPath}/build/"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
||||||
const ftlCommonPlaceholders = {
|
const ftlCommonPlaceholders = {
|
||||||
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }': loadFtlFile("template.ftl"),
|
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }': loadFtlFile("common.ftl"),
|
||||||
'<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->':
|
'<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->':
|
||||||
[
|
[
|
||||||
'<#if scripts??>',
|
'<#if scripts??>',
|
||||||
@ -89,9 +109,10 @@ export function generateFtlFilesCodeFactory(
|
|||||||
...(Object.keys(cssGlobalsToDefine).length === 0 ? [] : [
|
...(Object.keys(cssGlobalsToDefine).length === 0 ? [] : [
|
||||||
'',
|
'',
|
||||||
'<style>',
|
'<style>',
|
||||||
generateCssCodeToDefineGlobals(
|
generateCssCodeToDefineGlobals({
|
||||||
{ cssGlobalsToDefine }
|
cssGlobalsToDefine,
|
||||||
).cssCodeToPrependInHead,
|
urlPathname
|
||||||
|
}).cssCodeToPrependInHead,
|
||||||
'</style>',
|
'</style>',
|
||||||
''
|
''
|
||||||
]),
|
]),
|
||||||
|
@ -1,114 +0,0 @@
|
|||||||
<script>const _=
|
|
||||||
{
|
|
||||||
"url": {
|
|
||||||
"loginAction": "${url.loginAction?no_esc}",
|
|
||||||
"resourcesPath": "${url.resourcesPath?no_esc}",
|
|
||||||
"resourcesCommonPath": "${url.resourcesCommonPath?no_esc}",
|
|
||||||
"loginRestartFlowUrl": "${url.loginRestartFlowUrl?no_esc}",
|
|
||||||
"loginUrl": "${url.loginUrl?no_esc}"
|
|
||||||
},
|
|
||||||
"realm": {
|
|
||||||
"displayName": "${realm.displayName!''}" || undefined,
|
|
||||||
"displayNameHtml": "${realm.displayNameHtml!''}" || undefined,
|
|
||||||
"internationalizationEnabled": ${realm.internationalizationEnabled?c},
|
|
||||||
"registrationEmailAsUsername": ${realm.registrationEmailAsUsername?c},
|
|
||||||
},
|
|
||||||
"locale": (function (){
|
|
||||||
|
|
||||||
<#if realm.internationalizationEnabled>
|
|
||||||
|
|
||||||
return {
|
|
||||||
"supported": (function(){
|
|
||||||
|
|
||||||
<#if realm.internationalizationEnabled>
|
|
||||||
|
|
||||||
var out= [];
|
|
||||||
|
|
||||||
<#list locale.supported as lng>
|
|
||||||
out.push({
|
|
||||||
"url": "${lng.url?no_esc}",
|
|
||||||
"label": "${lng.label}",
|
|
||||||
"languageTag": "${lng.languageTag}"
|
|
||||||
});
|
|
||||||
</#list>
|
|
||||||
|
|
||||||
return out;
|
|
||||||
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
|
|
||||||
})(),
|
|
||||||
"current": "${locale.current}"
|
|
||||||
};
|
|
||||||
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
|
|
||||||
})(),
|
|
||||||
"auth": (function (){
|
|
||||||
|
|
||||||
|
|
||||||
<#if auth?has_content>
|
|
||||||
|
|
||||||
var out= {
|
|
||||||
"showUsername": ${auth.showUsername()?c},
|
|
||||||
"showResetCredentials": ${auth.showResetCredentials()?c},
|
|
||||||
"showTryAnotherWayLink": ${auth.showTryAnotherWayLink()?c},
|
|
||||||
};
|
|
||||||
|
|
||||||
<#if auth.showUsername() && !auth.showResetCredentials()>
|
|
||||||
Object.assign(
|
|
||||||
out,
|
|
||||||
{
|
|
||||||
"attemptedUsername": "${auth.attemptedUsername}"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
return out;
|
|
||||||
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
|
|
||||||
})(),
|
|
||||||
"scripts": (function(){
|
|
||||||
|
|
||||||
var out = [];
|
|
||||||
|
|
||||||
<#if scripts??>
|
|
||||||
<#list scripts as script>
|
|
||||||
out.push("${script}");
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
return out;
|
|
||||||
|
|
||||||
})(),
|
|
||||||
"message": (function (){
|
|
||||||
|
|
||||||
<#if message?has_content>
|
|
||||||
|
|
||||||
return {
|
|
||||||
"type": "${message.type}",
|
|
||||||
"summary": String.htmlUnescape("${message.summary}")
|
|
||||||
};
|
|
||||||
|
|
||||||
</#if>
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
|
|
||||||
})(),
|
|
||||||
"isAppInitiatedAction": (function (){
|
|
||||||
|
|
||||||
<#if isAppInitiatedAction??>
|
|
||||||
return true;
|
|
||||||
</#if>
|
|
||||||
return false;
|
|
||||||
|
|
||||||
})()
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -3,26 +3,28 @@ import { transformCodebase } from "../tools/transformCodebase";
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import {
|
import {
|
||||||
replaceImportFromStaticInCssCode,
|
replaceImportsInCssCode,
|
||||||
replaceImportFromStaticInJsCode
|
replaceImportsFromStaticInJsCode
|
||||||
} from "./replaceImportFromStatic";
|
} from "./replaceImportFromStatic";
|
||||||
import { generateFtlFilesCodeFactory, pageIds } from "./generateFtl";
|
import { generateFtlFilesCodeFactory, pageIds } from "./generateFtl";
|
||||||
import { builtinThemesUrl } from "../install-builtin-keycloak-themes";
|
import { builtinThemesUrl } from "../install-builtin-keycloak-themes";
|
||||||
import { downloadAndUnzip } from "../tools/downloadAndUnzip";
|
import { downloadAndUnzip } from "../tools/downloadAndUnzip";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import { ftlValuesGlobalName } from "./ftlValuesGlobalName";
|
import { ftlValuesGlobalName } from "./ftlValuesGlobalName";
|
||||||
import { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/kcContextMocks/urlResourcesPath";
|
import { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/kcContextMocks/urlResourcesPath";
|
||||||
import { isInside } from "../tools/isInside";
|
import { isInside } from "../tools/isInside";
|
||||||
|
|
||||||
|
|
||||||
export function generateKeycloakThemeResources(
|
export function generateKeycloakThemeResources(
|
||||||
params: {
|
params: {
|
||||||
themeName: string;
|
themeName: string;
|
||||||
reactAppBuildDirPath: string;
|
reactAppBuildDirPath: string;
|
||||||
keycloakThemeBuildingDirPath: string;
|
keycloakThemeBuildingDirPath: string;
|
||||||
|
urlPathname: string;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath } = params;
|
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath, urlPathname } = params;
|
||||||
|
|
||||||
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ export function generateKeycloakThemeResources(
|
|||||||
|
|
||||||
if (/\.css?$/i.test(filePath)) {
|
if (/\.css?$/i.test(filePath)) {
|
||||||
|
|
||||||
const { cssGlobalsToDefine, fixedCssCode } = replaceImportFromStaticInCssCode(
|
const { cssGlobalsToDefine, fixedCssCode } = replaceImportsInCssCode(
|
||||||
{ "cssCode": sourceCode.toString("utf8") }
|
{ "cssCode": sourceCode.toString("utf8") }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -59,9 +61,10 @@ export function generateKeycloakThemeResources(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (/\.js?$/i.test(filePath)) {
|
if (/\.js?$/i.test(filePath)) {
|
||||||
|
|
||||||
const { fixedJsCode } = replaceImportFromStaticInJsCode({
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
||||||
"jsCode": sourceCode.toString("utf8"),
|
"jsCode": sourceCode.toString("utf8"),
|
||||||
ftlValuesGlobalName
|
ftlValuesGlobalName
|
||||||
});
|
});
|
||||||
@ -80,7 +83,8 @@ export function generateKeycloakThemeResources(
|
|||||||
ftlValuesGlobalName,
|
ftlValuesGlobalName,
|
||||||
"indexHtmlCode": fs.readFileSync(
|
"indexHtmlCode": fs.readFileSync(
|
||||||
pathJoin(reactAppBuildDirPath, "index.html")
|
pathJoin(reactAppBuildDirPath, "index.html")
|
||||||
).toString("utf8")
|
).toString("utf8"),
|
||||||
|
urlPathname
|
||||||
});
|
});
|
||||||
|
|
||||||
pageIds.forEach(pageId => {
|
pageIds.forEach(pageId => {
|
||||||
|
@ -6,6 +6,7 @@ import type { ParsedPackageJson } from "./generateJavaStackFiles";
|
|||||||
import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path";
|
import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
|
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
|
||||||
|
import { URL } from "url";
|
||||||
|
|
||||||
|
|
||||||
const reactProjectDirPath = process.cwd();
|
const reactProjectDirPath = process.cwd();
|
||||||
@ -22,7 +23,25 @@ if (require.main === module) {
|
|||||||
generateKeycloakThemeResources({
|
generateKeycloakThemeResources({
|
||||||
keycloakThemeBuildingDirPath,
|
keycloakThemeBuildingDirPath,
|
||||||
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
||||||
"themeName": parsedPackageJson.name
|
"themeName": parsedPackageJson.name,
|
||||||
|
"urlPathname": (() => {
|
||||||
|
|
||||||
|
const url = (() => {
|
||||||
|
|
||||||
|
const { homepage } = parsedPackageJson;
|
||||||
|
|
||||||
|
return homepage === undefined ?
|
||||||
|
undefined :
|
||||||
|
new URL(homepage);
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
return url === undefined ?
|
||||||
|
"/" :
|
||||||
|
url.pathname.replace(/([^/])$/, "$1/");
|
||||||
|
|
||||||
|
|
||||||
|
})()
|
||||||
});
|
});
|
||||||
|
|
||||||
const { jarFilePath } = generateJavaStackFiles({
|
const { jarFilePath } = generateJavaStackFiles({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import * as crypto from "crypto";
|
import * as crypto from "crypto";
|
||||||
|
|
||||||
export function replaceImportFromStaticInJsCode(
|
export function replaceImportsFromStaticInJsCode(
|
||||||
params: {
|
params: {
|
||||||
ftlValuesGlobalName: string;
|
ftlValuesGlobalName: string;
|
||||||
jsCode: string;
|
jsCode: string;
|
||||||
@ -10,16 +10,36 @@ export function replaceImportFromStaticInJsCode(
|
|||||||
|
|
||||||
const { jsCode, ftlValuesGlobalName } = params;
|
const { jsCode, ftlValuesGlobalName } = params;
|
||||||
|
|
||||||
const fixedJsCode = jsCode!.replace(
|
const fixedJsCode = jsCode.replace(
|
||||||
/"static\//g,
|
/[a-z]+\.[a-z]+\+"static\//g,
|
||||||
`window.${ftlValuesGlobalName}.url.resourcesPath.replace(/^\\//,"") + "/build/static/`
|
`window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/`
|
||||||
);
|
);
|
||||||
|
|
||||||
return { fixedJsCode };
|
return { fixedJsCode };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceImportFromStaticInCssCode(
|
export function replaceImportsInInlineCssCode(
|
||||||
|
params: {
|
||||||
|
cssCode: string;
|
||||||
|
urlPathname: string;
|
||||||
|
}
|
||||||
|
): { fixedCssCode: string; } {
|
||||||
|
|
||||||
|
const { cssCode, urlPathname } = params;
|
||||||
|
|
||||||
|
const fixedCssCode = cssCode.replace(
|
||||||
|
urlPathname === "/" ?
|
||||||
|
/url\(\/([^/][^)]+)\)/g :
|
||||||
|
new RegExp(`url\\(${urlPathname}([^)]+)\\)`, "g"),
|
||||||
|
(...[, group]) => `url(${"${url.resourcesPath}/build/" + group})`
|
||||||
|
);
|
||||||
|
|
||||||
|
return { fixedCssCode };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function replaceImportsInCssCode(
|
||||||
params: {
|
params: {
|
||||||
cssCode: string;
|
cssCode: string;
|
||||||
}
|
}
|
||||||
@ -32,7 +52,7 @@ export function replaceImportFromStaticInCssCode(
|
|||||||
|
|
||||||
const cssGlobalsToDefine: Record<string, string> = {};
|
const cssGlobalsToDefine: Record<string, string> = {};
|
||||||
|
|
||||||
new Set(cssCode.match(/(url\(\/[^)]+\))/g) ?? [])
|
new Set(cssCode.match(/url\(\/[^/][^)]+\)[^;}]*/g) ?? [])
|
||||||
.forEach(match =>
|
.forEach(match =>
|
||||||
cssGlobalsToDefine[
|
cssGlobalsToDefine[
|
||||||
"url" + crypto
|
"url" + crypto
|
||||||
@ -60,12 +80,13 @@ export function replaceImportFromStaticInCssCode(
|
|||||||
export function generateCssCodeToDefineGlobals(
|
export function generateCssCodeToDefineGlobals(
|
||||||
params: {
|
params: {
|
||||||
cssGlobalsToDefine: Record<string, string>;
|
cssGlobalsToDefine: Record<string, string>;
|
||||||
|
urlPathname: string;
|
||||||
}
|
}
|
||||||
): {
|
): {
|
||||||
cssCodeToPrependInHead: string;
|
cssCodeToPrependInHead: string;
|
||||||
} {
|
} {
|
||||||
|
|
||||||
const { cssGlobalsToDefine } = params;
|
const { cssGlobalsToDefine, urlPathname } = params;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"cssCodeToPrependInHead": [
|
"cssCodeToPrependInHead": [
|
||||||
@ -73,12 +94,8 @@ export function generateCssCodeToDefineGlobals(
|
|||||||
...Object.keys(cssGlobalsToDefine)
|
...Object.keys(cssGlobalsToDefine)
|
||||||
.map(cssVariableName => [
|
.map(cssVariableName => [
|
||||||
`--${cssVariableName}:`,
|
`--${cssVariableName}:`,
|
||||||
[
|
cssGlobalsToDefine[cssVariableName]
|
||||||
"url(",
|
.replace(new RegExp(`url\\(${urlPathname.replace(/\//g, "\\/")}`, "g"), "url(${url.resourcesPath}/build/")
|
||||||
"${url.resourcesPath}/build" +
|
|
||||||
cssGlobalsToDefine[cssVariableName].match(/^url\(([^)]+)\)$/)![1],
|
|
||||||
")"
|
|
||||||
].join("")
|
|
||||||
].join(" "))
|
].join(" "))
|
||||||
.map(line => ` ${line};`),
|
.map(line => ` ${line};`),
|
||||||
"}"
|
"}"
|
||||||
|
@ -25,7 +25,7 @@ export type TemplateProps = {
|
|||||||
showUsernameNode?: ReactNode;
|
showUsernameNode?: ReactNode;
|
||||||
formNode: ReactNode;
|
formNode: ReactNode;
|
||||||
infoNode?: ReactNode;
|
infoNode?: ReactNode;
|
||||||
} & { kcContext: KcContext.Template; } & KcTemplateProps;
|
} & { kcContext: KcContext; } & KcTemplateProps;
|
||||||
|
|
||||||
export const Template = memo((props: TemplateProps) => {
|
export const Template = memo((props: TemplateProps) => {
|
||||||
|
|
||||||
|
@ -10,12 +10,17 @@ import type { LanguageLabel } from "./i18n/KcLanguageTag";
|
|||||||
type ExtractAfterStartingWith<Prefix extends string, StrEnum> =
|
type ExtractAfterStartingWith<Prefix extends string, StrEnum> =
|
||||||
StrEnum extends `${Prefix}${infer U}` ? U : never;
|
StrEnum extends `${Prefix}${infer U}` ? U : never;
|
||||||
|
|
||||||
|
/** Take theses type definition with a grain of salt.
|
||||||
|
* Some values might be undefined on some pages.
|
||||||
|
* (ex: url.loginAction is undefined on error.ftl)
|
||||||
|
*/
|
||||||
export type KcContext =
|
export type KcContext =
|
||||||
KcContext.Login | KcContext.Register | KcContext.Info |
|
KcContext.Login | KcContext.Register | KcContext.Info |
|
||||||
KcContext.Error | KcContext.LoginResetPassword | KcContext.LoginVerifyEmail;
|
KcContext.Error | KcContext.LoginResetPassword | KcContext.LoginVerifyEmail;
|
||||||
|
|
||||||
export declare namespace KcContext {
|
export declare namespace KcContext {
|
||||||
|
|
||||||
export type Template = {
|
export type Common = {
|
||||||
url: {
|
url: {
|
||||||
loginAction: string;
|
loginAction: string;
|
||||||
resourcesPath: string;
|
resourcesPath: string;
|
||||||
@ -27,7 +32,7 @@ export declare namespace KcContext {
|
|||||||
displayName?: string;
|
displayName?: string;
|
||||||
displayNameHtml?: string;
|
displayNameHtml?: string;
|
||||||
internationalizationEnabled: boolean;
|
internationalizationEnabled: boolean;
|
||||||
registrationEmailAsUsername: boolean; //<---
|
registrationEmailAsUsername: boolean;
|
||||||
};
|
};
|
||||||
/** Undefined if !realm.internationalizationEnabled */
|
/** Undefined if !realm.internationalizationEnabled */
|
||||||
locale?: {
|
locale?: {
|
||||||
@ -55,7 +60,7 @@ export declare namespace KcContext {
|
|||||||
isAppInitiatedAction: boolean;
|
isAppInitiatedAction: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Login = Template & {
|
export type Login = Common & {
|
||||||
pageId: "login.ftl";
|
pageId: "login.ftl";
|
||||||
url: {
|
url: {
|
||||||
loginResetCredentialsUrl: string;
|
loginResetCredentialsUrl: string;
|
||||||
@ -88,7 +93,7 @@ export declare namespace KcContext {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Register = Template & {
|
export type Register = Common & {
|
||||||
pageId: "register.ftl";
|
pageId: "register.ftl";
|
||||||
url: {
|
url: {
|
||||||
registrationAction: string;
|
registrationAction: string;
|
||||||
@ -120,7 +125,7 @@ export declare namespace KcContext {
|
|||||||
recaptchaSiteKey?: string;
|
recaptchaSiteKey?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Info = Template & {
|
export type Info = Common & {
|
||||||
pageId: "info.ftl";
|
pageId: "info.ftl";
|
||||||
messageHeader?: string;
|
messageHeader?: string;
|
||||||
requiredActions?: ExtractAfterStartingWith<"requiredAction.", MessageKey>[];
|
requiredActions?: ExtractAfterStartingWith<"requiredAction.", MessageKey>[];
|
||||||
@ -132,21 +137,21 @@ export declare namespace KcContext {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Error = Template & {
|
export type Error = Common & {
|
||||||
pageId: "error.ftl";
|
pageId: "error.ftl";
|
||||||
client?: {
|
client?: {
|
||||||
baseUrl?: string;
|
baseUrl?: string;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LoginResetPassword = Template & {
|
export type LoginResetPassword = Common & {
|
||||||
pageId: "login-reset-password.ftl";
|
pageId: "login-reset-password.ftl";
|
||||||
realm: {
|
realm: {
|
||||||
loginWithEmailAllowed: boolean;
|
loginWithEmailAllowed: boolean;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LoginVerifyEmail = Template & {
|
export type LoginVerifyEmail = Common & {
|
||||||
pageId: "login-verify-email.ftl";
|
pageId: "login-verify-email.ftl";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@ import { getKcLanguageTagLabel } from "../i18n/KcLanguageTag";
|
|||||||
//NOTE: Aside because we want to be able to import them from node
|
//NOTE: Aside because we want to be able to import them from node
|
||||||
import { resourcesCommonPath, resourcesPath } from "./urlResourcesPath";
|
import { resourcesCommonPath, resourcesPath } from "./urlResourcesPath";
|
||||||
|
|
||||||
export const kcTemplateContext: KcContext.Template = {
|
const kcCommonContext: KcContext.Common = {
|
||||||
"url": {
|
"url": {
|
||||||
"loginAction": "#",
|
"loginAction": "#",
|
||||||
"resourcesPath": "/" + resourcesPath,
|
"resourcesPath": `${process.env["PUBLIC_URL"]}/${resourcesPath}`,
|
||||||
"resourcesCommonPath": "/" + resourcesCommonPath,
|
"resourcesCommonPath": `${process.env["PUBLIC_URL"]}/${resourcesCommonPath}`,
|
||||||
"loginRestartFlowUrl": "/auth/realms/myrealm/login-actions/restart?client_id=account&tab_id=HoAx28ja4xg",
|
"loginRestartFlowUrl": "/auth/realms/myrealm/login-actions/restart?client_id=account&tab_id=HoAx28ja4xg",
|
||||||
"loginUrl": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg",
|
"loginUrl": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg",
|
||||||
},
|
},
|
||||||
@ -111,7 +111,7 @@ export const kcTemplateContext: KcContext.Template = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(
|
Object.defineProperty(
|
||||||
kcTemplateContext.locale!,
|
kcCommonContext.locale!,
|
||||||
"current",
|
"current",
|
||||||
{
|
{
|
||||||
"get": () => getKcLanguageTagLabel(getEvtKcLanguage().state),
|
"get": () => getKcLanguageTagLabel(getEvtKcLanguage().state),
|
||||||
@ -120,22 +120,22 @@ Object.defineProperty(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const kcLoginContext: KcContext.Login = {
|
export const kcLoginContext: KcContext.Login = {
|
||||||
...kcTemplateContext,
|
...kcCommonContext,
|
||||||
"pageId": "login.ftl",
|
"pageId": "login.ftl",
|
||||||
"url": {
|
"url": {
|
||||||
...kcTemplateContext.url,
|
...kcCommonContext.url,
|
||||||
"loginResetCredentialsUrl": "/auth/realms/myrealm/login-actions/reset-credentials?client_id=account&tab_id=HoAx28ja4xg",
|
"loginResetCredentialsUrl": "/auth/realms/myrealm/login-actions/reset-credentials?client_id=account&tab_id=HoAx28ja4xg",
|
||||||
"registrationUrl": "/auth/realms/myrealm/login-actions/registration?client_id=account&tab_id=HoAx28ja4xg"
|
"registrationUrl": "/auth/realms/myrealm/login-actions/registration?client_id=account&tab_id=HoAx28ja4xg"
|
||||||
},
|
},
|
||||||
"realm": {
|
"realm": {
|
||||||
...kcTemplateContext.realm,
|
...kcCommonContext.realm,
|
||||||
"loginWithEmailAllowed": true,
|
"loginWithEmailAllowed": true,
|
||||||
"rememberMe": true,
|
"rememberMe": true,
|
||||||
"password": true,
|
"password": true,
|
||||||
"resetPasswordAllowed": true,
|
"resetPasswordAllowed": true,
|
||||||
"registrationAllowed": true
|
"registrationAllowed": true
|
||||||
},
|
},
|
||||||
"auth": kcTemplateContext.auth!,
|
"auth": kcCommonContext.auth!,
|
||||||
"social": {
|
"social": {
|
||||||
"displayInfo": true
|
"displayInfo": true
|
||||||
},
|
},
|
||||||
@ -147,7 +147,7 @@ export const kcLoginContext: KcContext.Login = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const kcRegisterContext: KcContext.Register = {
|
export const kcRegisterContext: KcContext.Register = {
|
||||||
...kcTemplateContext,
|
...kcCommonContext,
|
||||||
"url": {
|
"url": {
|
||||||
...kcLoginContext.url,
|
...kcLoginContext.url,
|
||||||
"registrationAction": "http://localhost:8080/auth/realms/myrealm/login-actions/registration?session_code=gwZdUeO7pbYpFTRxiIxRg_QtzMbtFTKrNu6XW_f8asM&execution=12146ce0-b139-4bbd-b25b-0eccfee6577e&client_id=account&tab_id=uS8lYfebLa0"
|
"registrationAction": "http://localhost:8080/auth/realms/myrealm/login-actions/registration?session_code=gwZdUeO7pbYpFTRxiIxRg_QtzMbtFTKrNu6XW_f8asM&execution=12146ce0-b139-4bbd-b25b-0eccfee6577e&client_id=account&tab_id=uS8lYfebLa0"
|
||||||
@ -166,7 +166,7 @@ export const kcRegisterContext: KcContext.Register = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const kcInfoContext: KcContext.Info ={
|
export const kcInfoContext: KcContext.Info ={
|
||||||
...kcTemplateContext,
|
...kcCommonContext,
|
||||||
"pageId": "info.ftl",
|
"pageId": "info.ftl",
|
||||||
"messageHeader": "<Message header>",
|
"messageHeader": "<Message header>",
|
||||||
"requiredActions": undefined,
|
"requiredActions": undefined,
|
||||||
@ -178,7 +178,7 @@ export const kcInfoContext: KcContext.Info ={
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const kcErrorContext: KcContext.Error = {
|
export const kcErrorContext: KcContext.Error = {
|
||||||
...kcTemplateContext,
|
...kcCommonContext,
|
||||||
"pageId": "error.ftl",
|
"pageId": "error.ftl",
|
||||||
"client": {
|
"client": {
|
||||||
"baseUrl": "#"
|
"baseUrl": "#"
|
||||||
@ -186,16 +186,16 @@ export const kcErrorContext: KcContext.Error = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const kcLoginResetPasswordContext: KcContext.LoginResetPassword = {
|
export const kcLoginResetPasswordContext: KcContext.LoginResetPassword = {
|
||||||
...kcTemplateContext,
|
...kcCommonContext,
|
||||||
"pageId": "login-reset-password.ftl",
|
"pageId": "login-reset-password.ftl",
|
||||||
"realm":{
|
"realm":{
|
||||||
...kcTemplateContext.realm,
|
...kcCommonContext.realm,
|
||||||
"loginWithEmailAllowed": false
|
"loginWithEmailAllowed": false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const kcLoginVerifyEmailContext: KcContext.LoginVerifyEmail = {
|
export const kcLoginVerifyEmailContext: KcContext.LoginVerifyEmail = {
|
||||||
...kcTemplateContext,
|
...kcCommonContext,
|
||||||
"pageId": "login-verify-email.ftl"
|
"pageId": "login-verify-email.ftl"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,12 +66,11 @@ export function createKeycloakAdapter(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
"login": options => {
|
"login": options => {
|
||||||
window.location.replace(
|
window.location.href=
|
||||||
transformUrlBeforeRedirect(
|
transformUrlBeforeRedirect(
|
||||||
keycloakInstance.createLoginUrl(
|
keycloakInstance.createLoginUrl(
|
||||||
options
|
options
|
||||||
)
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
return neverResolvingPromise;
|
return neverResolvingPromise;
|
||||||
},
|
},
|
||||||
@ -86,13 +85,13 @@ export function createKeycloakAdapter(
|
|||||||
return neverResolvingPromise;
|
return neverResolvingPromise;
|
||||||
},
|
},
|
||||||
"register": options => {
|
"register": options => {
|
||||||
window.location.replace(
|
window.location.href =
|
||||||
transformUrlBeforeRedirect(
|
transformUrlBeforeRedirect(
|
||||||
keycloakInstance.createRegisterUrl(
|
keycloakInstance.createRegisterUrl(
|
||||||
options
|
options
|
||||||
)
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return neverResolvingPromise;
|
return neverResolvingPromise;
|
||||||
},
|
},
|
||||||
"accountManagement": () => {
|
"accountManagement": () => {
|
||||||
|
@ -9,8 +9,9 @@ import {
|
|||||||
setupSampleReactProject();
|
setupSampleReactProject();
|
||||||
|
|
||||||
generateKeycloakThemeResources({
|
generateKeycloakThemeResources({
|
||||||
"themeName": "onyxia-ui",
|
"themeName": "keycloakify-demo-app",
|
||||||
"reactAppBuildDirPath": pathJoin(sampleReactProjectDirPath, "build"),
|
"reactAppBuildDirPath": pathJoin(sampleReactProjectDirPath, "build"),
|
||||||
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme")
|
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme"),
|
||||||
|
"urlPathname": "/keycloakify-demo-app/"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
replaceImportFromStaticInJsCode,
|
replaceImportsFromStaticInJsCode,
|
||||||
replaceImportFromStaticInCssCode,
|
replaceImportsInCssCode,
|
||||||
generateCssCodeToDefineGlobals
|
generateCssCodeToDefineGlobals
|
||||||
} from "../bin/build-keycloak-theme/replaceImportFromStatic";
|
} from "../bin/build-keycloak-theme/replaceImportFromStatic";
|
||||||
|
|
||||||
const { fixedJsCode } = replaceImportFromStaticInJsCode({
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
||||||
"ftlValuesGlobalName": "keycloakFtlValues",
|
"ftlValuesGlobalName": "keycloakFtlValues",
|
||||||
"jsCode": `
|
"jsCode": `
|
||||||
function f() {
|
function f() {
|
||||||
@ -24,7 +24,7 @@ const { fixedJsCode } = replaceImportFromStaticInJsCode({
|
|||||||
|
|
||||||
console.log({ fixedJsCode });
|
console.log({ fixedJsCode });
|
||||||
|
|
||||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportFromStaticInCssCode({
|
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
||||||
"cssCode": `
|
"cssCode": `
|
||||||
|
|
||||||
.my-div {
|
.my-div {
|
||||||
@ -45,6 +45,6 @@ const { fixedCssCode, cssGlobalsToDefine } = replaceImportFromStaticInCssCode({
|
|||||||
console.log({ fixedCssCode, cssGlobalsToDefine });
|
console.log({ fixedCssCode, cssGlobalsToDefine });
|
||||||
|
|
||||||
|
|
||||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({ cssGlobalsToDefine });
|
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({ cssGlobalsToDefine, "urlPathname": "/" });
|
||||||
|
|
||||||
console.log({ cssCodeToPrependInHead });
|
console.log({ cssCodeToPrependInHead });
|
Reference in New Issue
Block a user