Compare commits
188 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b23d03ca5 | |||
7075be20c8 | |||
3ce8b06246 | |||
ee5c29f30f | |||
242dad3ea0 | |||
d8701925df | |||
e2d669ce31 | |||
af93664c71 | |||
daa3efa534 | |||
2c7c8397f0 | |||
821ba2cbe2 | |||
a17ddb02fa | |||
b89557e8d8 | |||
cad1f8b957 | |||
f82cc788bf | |||
06f9cd3e68 | |||
5113a838e7 | |||
645a84c82a | |||
925fc43d0f | |||
8e33d24c63 | |||
984ef63661 | |||
a8daf175ea | |||
055263a3da | |||
9990b0ab05 | |||
423397ce3e | |||
954567712c | |||
9f52eb8123 | |||
744b198fb4 | |||
15eab797c3 | |||
8ff86b1e29 | |||
e1b8760ee3 | |||
bd0d890b2c | |||
2a2118d769 | |||
9839b64650 | |||
2bf55e12f9 | |||
2249fa9232 | |||
f673a65304 | |||
0163459ad6 | |||
b21123cc9d | |||
7800d125b2 | |||
89ea648f18 | |||
ab7ac3c2d0 | |||
b16319d962 | |||
f8012d5dfb | |||
45a2015597 | |||
524ab000be | |||
d73cfb8765 | |||
8164f5373f | |||
824b0c275e | |||
f8d83d7a37 | |||
b291526b13 | |||
e1c310d383 | |||
242777a8eb | |||
10a6b70fe9 | |||
c829f5969c | |||
ba6a5047b1 | |||
852f48c05f | |||
c342f04a92 | |||
42eb8147c6 | |||
ebcdbd782f | |||
d2059e08d1 | |||
4f075882d5 | |||
044ec1a2da | |||
a49a32703d | |||
46ec832767 | |||
fc858b3db6 | |||
3cd8843157 | |||
c9358ea8dd | |||
354a4db0f6 | |||
90d435d96b | |||
2d804f0f0f | |||
1c9acedac0 | |||
6e914e4ea3 | |||
f0c4786267 | |||
0b16159312 | |||
ea8a91e069 | |||
59db202fe4 | |||
09927afd43 | |||
13c6122b9b | |||
1bb19f65a2 | |||
918a80cfb6 | |||
ed7d5eabcb | |||
2795109162 | |||
966f277628 | |||
36d60411f9 | |||
60fe33f3fd | |||
1df685df92 | |||
7894d95ace | |||
a8b4493aa1 | |||
715a7399cf | |||
a1e59bae23 | |||
b0819314a1 | |||
0099442543 | |||
66a0b07228 | |||
85f9544754 | |||
2f16a09ab8 | |||
183ae98c30 | |||
ba15e63879 | |||
654277feda | |||
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 | |||
0c0052e1cd | |||
78622770ec | |||
7b86727394 | |||
0965f8648e | |||
98974b4367 | |||
597bcadd9e | |||
4d9aabcb91 | |||
1606c2884d | |||
12f69b593f | |||
1ca45f90d0 | |||
a91a5616f9 | |||
c525e09368 | |||
f5bba4a6a0 | |||
77a37fb573 | |||
6b24c5878c | |||
f4414e1249 | |||
b72971f4ce | |||
b9af4e6804 | |||
2fd1d42d1e | |||
3cfc7d7fa9 | |||
b5d9055fcf | |||
63d644d95f | |||
e16192b416 | |||
505e018448 | |||
5ced0e2809 | |||
0e1d919f7e | |||
a009db998e | |||
d6c6bd933b | |||
859cc03f35 | |||
1a3b8ae3b8 | |||
863a08abf3 | |||
fd9c6afa5e | |||
8f3797407b | |||
7eedb23285 | |||
e4a2c95dd8 | |||
9429228b71 | |||
aafbc60f12 |
164
.github/workflows/ci.yaml
vendored
164
.github/workflows/ci.yaml
vendored
@ -2,14 +2,14 @@ name: ci
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
test_node:
|
test:
|
||||||
runs-on: macos-10.15
|
runs-on: macos-10.15
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
@ -17,72 +17,120 @@ jobs:
|
|||||||
name: Test with Node v${{ matrix.node }}
|
name: Test with Node v${{ matrix.node }}
|
||||||
steps:
|
steps:
|
||||||
- name: Tell if project is using npm or yarn
|
- name: Tell if project is using npm or yarn
|
||||||
id: _1
|
id: step1
|
||||||
uses: garronej/github_actions_toolkit@v1.11
|
uses: garronej/github_actions_toolkit@v2.2
|
||||||
with:
|
with:
|
||||||
action_name: tell_if_project_uses_npm_or_yarn
|
action_name: tell_if_project_uses_npm_or_yarn
|
||||||
owner: ${{github.repository_owner}}
|
- uses: actions/checkout@v2.3.4
|
||||||
repo: ${{github.event.repository.name}}
|
- uses: actions/setup-node@v2.1.3
|
||||||
branch: ${{github.ref}}
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions/setup-node@v1
|
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- if: steps._1.outputs.npm_or_yarn == 'yarn'
|
- if: steps.step1.outputs.npm_or_yarn == 'yarn'
|
||||||
run: |
|
run: |
|
||||||
yarn install --frozen-lockfile
|
yarn install --frozen-lockfile
|
||||||
yarn run build
|
yarn build
|
||||||
yarn run test
|
yarn test
|
||||||
- if: steps._1.outputs.npm_or_yarn == 'npm'
|
- if: steps.step1.outputs.npm_or_yarn == 'npm'
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
npm run test
|
npm test
|
||||||
trigger_publish:
|
check_if_version_upgraded:
|
||||||
name: Trigger publish.yaml workflow if package.json version updated ( and secrets.PAT is set ).
|
name: Check if version upgrade
|
||||||
|
if: github.event_name == 'push'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
needs: test
|
||||||
PAT: ${{secrets.PAT}}
|
outputs:
|
||||||
if: github.event_name == 'push' && github.event.head_commit.author.name != 'ts_ci'
|
from_version: ${{ steps.step1.outputs.from_version }}
|
||||||
needs: test_node
|
to_version: ${{ steps.step1.outputs.to_version }}
|
||||||
|
is_upgraded_version: ${{steps.step1.outputs.is_upgraded_version }}
|
||||||
steps:
|
steps:
|
||||||
|
- uses: garronej/github_actions_toolkit@v2.2
|
||||||
- name: Get version on latest
|
id: step1
|
||||||
id: v_latest
|
|
||||||
uses: garronej/github_actions_toolkit@v1.11
|
|
||||||
with:
|
with:
|
||||||
action_name: get_package_json_version
|
action_name: is_package_json_version_upgraded
|
||||||
owner: ${{github.repository_owner}}
|
|
||||||
repo: ${{github.event.repository.name}}
|
|
||||||
branch: latest
|
|
||||||
compare_to_version: '0.0.0'
|
|
||||||
|
|
||||||
- name: Get version on develop
|
update_changelog:
|
||||||
id: v_develop
|
runs-on: ubuntu-latest
|
||||||
uses: garronej/github_actions_toolkit@v1.11
|
needs: check_if_version_upgraded
|
||||||
with:
|
if: needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true'
|
||||||
action_name: get_package_json_version
|
steps:
|
||||||
owner: ${{github.repository_owner}}
|
- uses: garronej/github_actions_toolkit@v2.2
|
||||||
repo: ${{github.event.repository.name}}
|
|
||||||
branch: ${{ github.sha }}
|
|
||||||
compare_to_version: ${{steps.v_latest.outputs.version || '0.0.0'}}
|
|
||||||
|
|
||||||
- name: 'Trigger the ''publish'' workflow'
|
|
||||||
if: ${{ !!env.PAT && steps.v_develop.outputs.compare_result == '1' }}
|
|
||||||
uses: garronej/github_actions_toolkit@v1.11
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
with:
|
with:
|
||||||
action_name: dispatch_event
|
action_name: update_changelog
|
||||||
owner: ${{github.repository_owner}}
|
branch: ${{ github.ref }}
|
||||||
repo: ${{github.event.repository.name}}
|
commit_author_email: ts_ci@github.com
|
||||||
event_type: publish
|
|
||||||
client_payload_json: |
|
create_github_release:
|
||||||
${{
|
runs-on: ubuntu-latest
|
||||||
format(
|
needs:
|
||||||
'{{"from_version":"{0}","to_version":"{1}","repo":"{2}"}}',
|
- update_changelog
|
||||||
steps.v_latest.outputs.version,
|
- check_if_version_upgraded
|
||||||
steps.v_develop.outputs.version,
|
steps:
|
||||||
github.event.repository.name
|
- uses: actions/checkout@v2
|
||||||
)
|
with:
|
||||||
}}
|
ref: ${{ github.ref }}
|
||||||
|
- name: Build GitHub release body
|
||||||
|
id: step1
|
||||||
|
run: |
|
||||||
|
if [ "$FROM_VERSION" = "0.0.0" ]; then
|
||||||
|
echo "::set-output name=body::🚀"
|
||||||
|
else
|
||||||
|
echo "::set-output name=body::📋 [CHANGELOG](https://github.com/$GITHUB_REPOSITORY/blob/v$TO_VERSION/CHANGELOG.md)"
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
FROM_VERSION: ${{ needs.check_if_version_upgraded.outputs.from_version }}
|
||||||
|
TO_VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }}
|
||||||
|
- uses: garronej/action-gh-release@v0.2.0
|
||||||
|
with:
|
||||||
|
name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }}
|
||||||
|
tag_name: v${{ needs.check_if_version_upgraded.outputs.to_version }}
|
||||||
|
target_commitish: ${{ github.ref }}
|
||||||
|
body: ${{ steps.step1.outputs.body }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
publish_on_npm:
|
||||||
|
runs-on: macos-10.15
|
||||||
|
needs:
|
||||||
|
- update_changelog
|
||||||
|
- check_if_version_upgraded
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2.3.4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
- uses: actions/setup-node@v2.1.3
|
||||||
|
with:
|
||||||
|
node-version: '15'
|
||||||
|
- run: |
|
||||||
|
PACKAGE_MANAGER=npm
|
||||||
|
if [ -f "./yarn.lock" ]; then
|
||||||
|
PACKAGE_MANAGER=yarn
|
||||||
|
fi
|
||||||
|
if [ "$PACKAGE_MANAGER" = "yarn" ]; then
|
||||||
|
yarn install --frozen-lockfile
|
||||||
|
else
|
||||||
|
npm ci
|
||||||
|
fi
|
||||||
|
$PACKAGE_MANAGER run build
|
||||||
|
- run: npx -y -p denoify@0.6.5 denoify_enable_short_npm_import_path
|
||||||
|
env:
|
||||||
|
DRY_RUN: "0"
|
||||||
|
- name: Publishing on NPM
|
||||||
|
run: |
|
||||||
|
if [ "$(npm show . version)" = "$VERSION" ]; then
|
||||||
|
echo "This version is already published"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [ "$NPM_TOKEN" = "" ]; then
|
||||||
|
echo "Can't publish on NPM, You must first create a secret called NPM_TOKEN that contains your NPM auth token. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets"
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
|
||||||
|
npm publish
|
||||||
|
rm .npmrc
|
||||||
|
env:
|
||||||
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }}
|
116
.github/workflows/publish.yaml
vendored
116
.github/workflows/publish.yaml
vendored
@ -1,116 +0,0 @@
|
|||||||
on:
|
|
||||||
repository_dispatch:
|
|
||||||
types: publish
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
update_changelog_and_sync_package_lock_version:
|
|
||||||
name: Update CHANGELOG.md and make sure package.json and package-lock.json versions matches.
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Synchronize package.json and package-lock.json version if needed.
|
|
||||||
uses: garronej/github_actions_toolkit@v1.11
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
with:
|
|
||||||
action_name: sync_package_and_package_lock_version
|
|
||||||
owner: ${{github.repository_owner}}
|
|
||||||
repo: ${{github.event.client_payload.repo}}
|
|
||||||
branch: develop
|
|
||||||
commit_author_email: ts_ci@github.com
|
|
||||||
- name: Update CHANGELOG.md
|
|
||||||
if: ${{ !!github.event.client_payload.from_version }}
|
|
||||||
uses: garronej/github_actions_toolkit@v1.11
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
with:
|
|
||||||
action_name: update_changelog
|
|
||||||
owner: ${{github.repository_owner}}
|
|
||||||
repo: ${{github.event.client_payload.repo}}
|
|
||||||
branch_behind: latest
|
|
||||||
branch_ahead: develop
|
|
||||||
commit_author_email: ts_ci@github.com
|
|
||||||
exclude_commit_from_author_names_json: '["ts_ci"]'
|
|
||||||
|
|
||||||
publish:
|
|
||||||
runs-on: macos-10.15
|
|
||||||
needs: update_changelog_and_sync_package_lock_version
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
ref: develop
|
|
||||||
- name: Remove .github directory, useless on 'latest' branch
|
|
||||||
run: rm -r .github
|
|
||||||
- name: Remove branch 'latest'
|
|
||||||
continue-on-error: true
|
|
||||||
run: |
|
|
||||||
git branch -d latest || true
|
|
||||||
git push origin :latest
|
|
||||||
- name: Create the new 'latest' branch
|
|
||||||
run: |
|
|
||||||
git branch latest
|
|
||||||
git checkout latest
|
|
||||||
- uses: actions/setup-node@v1
|
|
||||||
- run: |
|
|
||||||
if [ -f "./yarn.lock" ]; then
|
|
||||||
yarn install --frozen-lockfile
|
|
||||||
else
|
|
||||||
npm ci
|
|
||||||
fi
|
|
||||||
- run: |
|
|
||||||
PACKAGE_MANAGER=npm
|
|
||||||
if [ -f "./yarn.lock" ]; then
|
|
||||||
PACKAGE_MANAGER=yarn
|
|
||||||
fi
|
|
||||||
$PACKAGE_MANAGER run enable_short_import_path
|
|
||||||
env:
|
|
||||||
DRY_RUN: "0"
|
|
||||||
- name: (DEBUG) Show how the files have been moved to enable short import
|
|
||||||
run: ls -lR
|
|
||||||
- name: Publishing on NPM
|
|
||||||
run: |
|
|
||||||
if [ "$(npm show . version)" = "$VERSION" ]; then
|
|
||||||
echo "This version is already published"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
if [ "$NPM_TOKEN" = "" ]; then
|
|
||||||
echo "Can't publish on NPM, You must first create a secret called NPM_TOKEN that contains your NPM auth token. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets"
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
|
|
||||||
npm publish
|
|
||||||
rm .npmrc
|
|
||||||
env:
|
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
VERSION: ${{ github.event.client_payload.to_version }}
|
|
||||||
- name: Commit changes
|
|
||||||
run: |
|
|
||||||
git config --local user.email "ts_ci@github.com"
|
|
||||||
git config --local user.name "ts_ci"
|
|
||||||
git add -A
|
|
||||||
git commit -am "Enabling shorter import paths [automatic]"
|
|
||||||
- run: git push origin latest
|
|
||||||
- name: Release body
|
|
||||||
id: id_rb
|
|
||||||
run: |
|
|
||||||
if [ "$FROM_VERSION" = "" ]; then
|
|
||||||
echo "::set-output name=body::🚀"
|
|
||||||
else
|
|
||||||
echo "::set-output name=body::📋 [CHANGELOG](https://github.com/$OWNER/$REPO/blob/$REF/CHANGELOG.md)"
|
|
||||||
fi
|
|
||||||
env:
|
|
||||||
FROM_VERSION: ${{ github.event.client_payload.from_version }}
|
|
||||||
OWNER: ${{github.repository_owner}}
|
|
||||||
REPO: ${{github.event.client_payload.repo}}
|
|
||||||
REF: v${{github.event.client_payload.to_version}}
|
|
||||||
- name: Create Release
|
|
||||||
uses: garronej/create-release@master
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
with:
|
|
||||||
tag_name: v${{ github.event.client_payload.to_version }}
|
|
||||||
release_name: Release v${{ github.event.client_payload.to_version }}
|
|
||||||
branch: latest
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
body: ${{ steps.id_rb.outputs.body }}
|
|
191
CHANGELOG.md
191
CHANGELOG.md
@ -1,3 +1,194 @@
|
|||||||
|
### **1.1.1** (2021-06-14)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## **1.1.0** (2021-06-14)
|
||||||
|
|
||||||
|
- Add login-idp-link-confirm.ftl
|
||||||
|
- Fix login-update-profile.ftl
|
||||||
|
- Add login-update-profile.ftl page
|
||||||
|
- Fix default background bug
|
||||||
|
- Remove unused 'markdown' dependency
|
||||||
|
- Fix warning related to powerhooks_useGlobalState_kcLanguageTag
|
||||||
|
- Update README.md
|
||||||
|
|
||||||
|
### **1.0.4** (2021-05-28)
|
||||||
|
|
||||||
|
- Instructions for custom themes with custom components
|
||||||
|
|
||||||
|
### **1.0.3** (2021-05-23)
|
||||||
|
|
||||||
|
- Instuction about how to integrate with non CRA projects
|
||||||
|
- Add mention to awesome list
|
||||||
|
|
||||||
|
### **1.0.2** (2021-05-01)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### **1.0.1** (2021-05-01)
|
||||||
|
|
||||||
|
- Fix: LoginOtp (and not otc)
|
||||||
|
|
||||||
|
# **1.0.0** (2021-05-01)
|
||||||
|
|
||||||
|
- #4: Guide for implementing a missing page
|
||||||
|
- Support OTP #4
|
||||||
|
|
||||||
|
### **0.4.4** (2021-04-29)
|
||||||
|
|
||||||
|
- Fix previous release
|
||||||
|
|
||||||
|
### **0.4.3** (2021-04-29)
|
||||||
|
|
||||||
|
- Add infos about the plugin that defines authorizedMailDomains
|
||||||
|
|
||||||
|
### **0.4.2** (2021-04-29)
|
||||||
|
|
||||||
|
- Client side validation of allowed email domains
|
||||||
|
- Support email whitlisting
|
||||||
|
- Restore kickstart video in the readme
|
||||||
|
- Update README.md
|
||||||
|
- Update README.md
|
||||||
|
- Important readme update
|
||||||
|
|
||||||
|
### **0.4.1** (2021-04-11)
|
||||||
|
|
||||||
|
- Quietly re-introduce --external-assets
|
||||||
|
- Give example of customization
|
||||||
|
|
||||||
|
## **0.4.0** (2021-04-09)
|
||||||
|
|
||||||
|
- Acual support of Therms of services
|
||||||
|
|
||||||
|
### **0.3.24** (2021-04-08)
|
||||||
|
|
||||||
|
- Add missing dependency: markdown
|
||||||
|
|
||||||
|
### **0.3.23** (2021-04-08)
|
||||||
|
|
||||||
|
- Allow to lazily load therms
|
||||||
|
|
||||||
|
### **0.3.22** (2021-04-08)
|
||||||
|
|
||||||
|
- update powerhooks
|
||||||
|
- Support terms and condition
|
||||||
|
- Fix info.ftl
|
||||||
|
- For useKcMessage we prefer returning callbacks with a changing references
|
||||||
|
|
||||||
|
### **0.3.21** (2021-04-04)
|
||||||
|
|
||||||
|
- Update powerhooks
|
||||||
|
|
||||||
|
### **0.3.20** (2021-04-01)
|
||||||
|
|
||||||
|
- Always catch freemarker errors
|
||||||
|
|
||||||
|
### **0.3.19** (2021-04-01)
|
||||||
|
|
||||||
|
- Fix previous release
|
||||||
|
|
||||||
|
### **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)
|
||||||
|
|
||||||
|
- Fix submit not receving correct text
|
||||||
|
|
||||||
|
### **0.3.2** (2021-03-21)
|
||||||
|
|
||||||
|
- Fix broken previous release
|
||||||
|
|
||||||
|
### **0.3.1** (2021-03-21)
|
||||||
|
|
||||||
|
- kcHeaderClass can be updated after initial mount
|
||||||
|
|
||||||
|
## **0.3.0** (2021-03-20)
|
||||||
|
|
||||||
|
- Bump version
|
||||||
|
- Feat: Cary over states using URL search params
|
||||||
|
- Bugfix: with kcHtmlClass
|
||||||
|
|
||||||
|
### **0.2.10** (2021-03-19)
|
||||||
|
|
||||||
|
- Remove dependency to denoify
|
||||||
|
|
||||||
|
### **0.2.9** (2021-03-19)
|
||||||
|
|
||||||
|
- Update deps and CI workflow
|
||||||
|
|
||||||
|
### **0.2.8** (2021-03-19)
|
||||||
|
|
||||||
|
- Bugfix: keycloak_build that grow and grow in size
|
||||||
|
- Add disclaimer about maitainment strategy
|
||||||
|
- Add a note for tested version support
|
||||||
|
|
||||||
|
### **0.2.7** (2021-03-13)
|
||||||
|
|
||||||
|
- Bump version
|
||||||
|
- Update README.md
|
||||||
|
- Update README.md
|
||||||
|
|
||||||
|
### **0.2.6** (2021-03-10)
|
||||||
|
|
||||||
|
- Fix generated gitignore
|
||||||
|
|
||||||
### **0.2.5** (2021-03-10)
|
### **0.2.5** (2021-03-10)
|
||||||
|
|
||||||
- Fix generated .gitignore
|
- Fix generated .gitignore
|
||||||
|
343
README.md
343
README.md
@ -2,81 +2,156 @@
|
|||||||
<img src="https://user-images.githubusercontent.com/6702424/109387840-eba11f80-7903-11eb-9050-db1dad883f78.png">
|
<img src="https://user-images.githubusercontent.com/6702424/109387840-eba11f80-7903-11eb-9050-db1dad883f78.png">
|
||||||
</p>
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<i>🔏 Customize key cloak's pages as if they were part of your App 🔏</i>
|
<i>🔏 Create Keycloak themes using React 🔏</i>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<img src="https://github.com/garronej/keycloakify/workflows/ci/badge.svg?branch=develop">
|
<img src="https://github.com/garronej/keycloakify/workflows/ci/badge.svg?branch=develop">
|
||||||
<img src="https://img.shields.io/bundlephobia/minzip/keycloakify">
|
<img src="https://img.shields.io/bundlephobia/minzip/keycloakify">
|
||||||
<img src="https://img.shields.io/npm/dw/keycloakify">
|
<img src="https://img.shields.io/npm/dw/keycloakify">
|
||||||
<img src="https://img.shields.io/npm/l/keycloakify">
|
<img src="https://img.shields.io/npm/l/keycloakify">
|
||||||
|
<img src="https://camo.githubusercontent.com/0f9fcc0ac1b8617ad4989364f60f78b2d6b32985ad6a508f215f14d8f897b8d3/68747470733a2f2f62616467656e2e6e65742f62616467652f547970655363726970742f7374726963742532302546302539462539322541412f626c7565">
|
||||||
|
<a href="https://github.com/thomasdarimont/awesome-keycloak">
|
||||||
|
<img src="https://awesome.re/mentioned-badge.svg"/>
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<i>Ultimately this build tool Generates a Keycloak theme</i>
|
<i>Ultimately this build tool generates a Keycloak theme</i>
|
||||||
<img src="https://user-images.githubusercontent.com/6702424/110260457-a1c3d380-7fac-11eb-853a-80459b65626b.png">
|
<img src="https://user-images.githubusercontent.com/6702424/110260457-a1c3d380-7fac-11eb-853a-80459b65626b.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Motivations
|
# Motivations
|
||||||
|
|
||||||
The problem:
|
Keycloak provides [theme support](https://www.keycloak.org/docs/latest/server_development/#_themes) for web pages. This allows customizing the look and feel of end-user facing pages so they can be integrated with your applications.
|
||||||
|
It involves, however, a lot of raw JS/CSS/[FTL]() hacking, and bundling the theme is not exactly straightforward.
|
||||||
|
|
||||||

|
Beyond that, if you use Keycloak for a specific app you want your login page to be tightly integrated with it.
|
||||||
|
Ideally, you don't want the user to notice when he is being redirected away.
|
||||||
|
|
||||||
When we redirected to Keycloak the user suffers from a harsh context switch.
|
Trying to reproduce the look and feel of a specific app in another stack is not an easy task not to mention
|
||||||
Keycloak does offer a way to customize theses pages but it requires a lot of raw HTML/CSS hacking
|
the cheer amount of maintenance that it involves.
|
||||||
to reproduce the look and feel of a specific app. Not mentioning the maintenance cost of such an endeavour.
|
|
||||||
|
|
||||||
Wouldn't it be great if we could just design the login and register pages as if they where part of our app?
|
<p align="center">
|
||||||
Here is `yarn add keycloakify` for you 🍸
|
<i>Without keycloakify, users suffers from a harsh context switch, no fronted form pre-validation</i><br>
|
||||||
|
<img src="https://user-images.githubusercontent.com/6702424/108838381-dbbbcf80-75d3-11eb-8ae8-db41563ef9db.gif">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
Wouldn't it be great if we could just design the login and register pages as if they were part of our app?
|
||||||
|
Here is `keycloakify` for you 🍸
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<i> <a href="https://datalab.sspcloud.fr">With keycloakify:</a> </i>
|
||||||
|
<br>
|
||||||
|
<img src="https://user-images.githubusercontent.com/6702424/114332075-c5e37900-9b45-11eb-910b-48a05b3d90d9.gif">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
**TL;DR**: [Here](https://github.com/garronej/keycloakify-demo-app) is a Hello World React project with Keycloakify set up.
|
||||||
|
|
||||||
|
If you already have a Keycloak custom theme, it can be easily ported to Keycloakify.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
TODO: Insert video after.
|
|
||||||
|
|
||||||
- [Motivations](#motivations)
|
- [Motivations](#motivations)
|
||||||
|
- [Requirements](#requirements)
|
||||||
|
- [My framework doesn’t seem to be supported, what can I do?](#my-framework-doesnt-seem-to-be-supported-what-can-i-do)
|
||||||
- [How to use](#how-to-use)
|
- [How to use](#how-to-use)
|
||||||
- [Setting up the build tool](#setting-up-the-build-tool)
|
- [Setting up the build tool](#setting-up-the-build-tool)
|
||||||
- [Developing your login and register pages in your React app](#developing-your-login-and-register-pages-in-your-react-app)
|
- [Changing just the look of the default Keycloak theme](#changing-just-the-look-of-the-default-keycloak-theme)
|
||||||
- [Just changing the look](#just-changing-the-look)
|
|
||||||
- [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)
|
||||||
- [How to implement context persistance](#how-to-implement-context-persistance)
|
- [Enable loading in a blink of an eye of login pages ⚡ (--external-assets)](#enable-loading-in-a-blink-of-an-eye-of-login-pages----external-assets)
|
||||||
- [If your keycloak is a subdomain of your app.](#if-your-keycloak-is-a-subdomain-of-your-app)
|
- [Support for Terms and conditions](#support-for-terms-and-conditions)
|
||||||
- [Else](#else)
|
- [Some pages still have the default theme. Why?](#some-pages-still-have-the-default-theme-why)
|
||||||
- [GitHub Actions](#github-actions)
|
- [GitHub Actions](#github-actions)
|
||||||
- [REQUIREMENTS](#requirements)
|
- [Limitations](#limitations)
|
||||||
- [API Reference](#api-reference)
|
- [`process.env.PUBLIC_URL` not supported.](#processenvpublic_url-not-supported)
|
||||||
- [The build tool](#the-build-tool)
|
- [`@font-face` importing fonts from the `src/` dir](#font-face-importing-fonts-from-thesrc-dir)
|
||||||
- [The fronted lib ( imported into your react app )](#the-fronted-lib--imported-into-your-react-app-)
|
- [Example of setup that **won't** work](#example-of-setup-that-wont-work)
|
||||||
|
- [Possible workarounds](#possible-workarounds)
|
||||||
|
- [Implement context persistence (optional)](#implement-context-persistence-optional)
|
||||||
|
- [Kickstart video](#kickstart-video)
|
||||||
|
- [Email domain whitelist](#email-domain-whitelist)
|
||||||
|
|
||||||
|
# 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 Keycloak v11.
|
||||||
|
|
||||||
|
This tool 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
|
||||||
|
and a `build/static/` directory generated by webpack.
|
||||||
|
For more information see [this issue](https://github.com/InseeFrLab/keycloakify/issues/5#issuecomment-832296432)
|
||||||
|
## My framework doesn’t seem to be supported, what can I do?
|
||||||
|
|
||||||
|
Currently Keycloakify is only compatible with `create-react-app` apps.
|
||||||
|
It doesn’t mean that you can't use Keycloakify if you are using Next.js, Express or any other
|
||||||
|
framework that involves SSR but your Keycloak theme will need to be a standalone project.
|
||||||
|
Find specific instructions about how to get started [**here**](https://github.com/garronej/keycloakify-demo-app#keycloak-theme-only).
|
||||||
|
|
||||||
|
To share your styles between your main app and your login pages you will need to externalize your design system by making it a
|
||||||
|
separate module. Checkout [ts_ci](https://github.com/garronej/ts_ci), it can help with that.
|
||||||
# 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`
|
```bash
|
||||||
then configure your `package.json` build's script to build the keycloak's theme by adding `&& build-keycloak-theme`.
|
yarn add keycloakify
|
||||||
|
|
||||||
Typically you will get:
|
|
||||||
|
|
||||||
`package.json`
|
|
||||||
```json
|
|
||||||
"devDependencies": {
|
|
||||||
"keycloakify": "^0.0.10"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "react-scripts build && build-keycloak-theme"
|
|
||||||
},
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then build your app with `yarn run build` or `npm run build`, you will be provided with instructions
|
[`package.json`](https://github.com/garronej/keycloakify-demo-app/blob/main/package.json)
|
||||||
about how to load the theme into Keycloak.
|
```json
|
||||||
|
"scripts": {
|
||||||
|
"keycloak": "yarn build && build-keycloak-theme",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Developing your login and register pages in your React app
|
```bash
|
||||||
|
yarn keycloak # generates keycloak-theme.jar
|
||||||
|
```
|
||||||
|
|
||||||
### Just changing the look
|
On the console will be printed all the instructions about how to load the generated theme in Keycloak
|
||||||
|
|
||||||
The fist approach is to only arr/replace the default class names by your
|
### Changing just the look of the default Keycloak theme
|
||||||
own.
|
|
||||||
|
|
||||||
|
The first approach is to only customize the style of the default Keycloak login by providing
|
||||||
|
your own class names.
|
||||||
|
|
||||||
|
If you have created a new React project specifically to create a Keycloak theme and nothing else then
|
||||||
|
your index should look something like:
|
||||||
|
|
||||||
|
`src/index.tsx`
|
||||||
```tsx
|
```tsx
|
||||||
|
import { App } from "./<wherever>/App";
|
||||||
|
import {
|
||||||
|
KcApp,
|
||||||
|
defaultKcProps,
|
||||||
|
kcContext
|
||||||
|
} from "keycloakify";
|
||||||
|
import { css } from "tss-react";
|
||||||
|
|
||||||
|
const myClassName = css({ "color": "red" });
|
||||||
|
|
||||||
|
reactDom.render(
|
||||||
|
<KcApp
|
||||||
|
kcContext={kcContext}
|
||||||
|
{...{
|
||||||
|
...defaultKcProps,
|
||||||
|
"kcHeaderWrapperClass": myClassName
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
document.getElementById("root")
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
If you share a unique project for your app and the Keycloak theme, your index should look
|
||||||
|
more like this:
|
||||||
|
|
||||||
|
`src/index.tsx`
|
||||||
|
```tsx
|
||||||
import { App } from "./<wherever>/App";
|
import { App } from "./<wherever>/App";
|
||||||
import {
|
import {
|
||||||
KcApp,
|
KcApp,
|
||||||
@ -103,23 +178,48 @@ reactDom.render(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
<i>result:</i>
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://user-images.githubusercontent.com/6702424/110261408-688d6280-7fb0-11eb-9822-7003d268b459.png">
|
<i>result:</i></br>
|
||||||
|
<img src="https://user-images.githubusercontent.com/6702424/114326299-6892fc00-9b34-11eb-8d75-85696e55458f.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
Example of a customization using only CSS: [here](https://github.com/InseeFrLab/onyxia-ui/blob/012639d62327a9a56be80c46e32c32c9497b82db/src/app/components/KcApp.tsx)
|
||||||
|
(the [index.tsx](https://github.com/InseeFrLab/onyxia-ui/blob/012639d62327a9a56be80c46e32c32c9497b82db/src/app/index.tsx#L89-L94) )
|
||||||
|
and the result you can expect:
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<i> <a href="https://datalab.sspcloud.fr">Customization using only CSS:</a> </i>
|
||||||
|
<br>
|
||||||
|
<img src="https://github.com/InseeFrLab/keycloakify/releases/download/v0.3.8/keycloakify_after.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### Changing the look **and** feel
|
### Changing the look **and** feel
|
||||||
|
|
||||||
If you want to really re-implement the pages the best approach is to
|
If you want to really re-implement the pages, the best approach is to
|
||||||
create you own version of the [`<KcApp />`](https://github.com/garronej/keycloakify/blob/develop/src/lib/components/KcApp.tsx).
|
create your own version of the [`<KcApp />`](https://github.com/garronej/keycloakify/blob/develop/src/lib/components/KcApp.tsx).
|
||||||
Copy/past some of [the components](https://github.com/garronej/keycloakify/tree/develop/src/lib/components) provided by this module and start hacking around.
|
Copy/past some of [the components](https://github.com/garronej/keycloakify/tree/develop/src/lib/components) provided by this module and start hacking around.
|
||||||
|
|
||||||
|
You can find an example of such customization [here](https://github.com/InseeFrLab/onyxia-ui/tree/master/src/app/components/KcApp).
|
||||||
|
|
||||||
|
And you can test the result in production by trying the login register page of [Onyxia](https://datalab.sspcloud.fr)
|
||||||
|
|
||||||
|
Note that you don’t have to re write **all** components, only the ones that you most need customized.
|
||||||
|
Look at [here for example](https://github.com/InseeFrLab/onyxia-ui/blob/3bf18aa82b198fc6ba7998c30abf0a9ae54a58b1/src/app/components/KcApp/KcApp.tsx#L112-L120).
|
||||||
|
We want to have our very own login and register page, so we wrote customs [Login.tsx](https://github.com/InseeFrLab/onyxia-ui/blob/master/src/app/components/KcApp/Login.tsx) and [Register.txs](https://github.com/InseeFrLab/onyxia-ui/blob/master/src/app/components/KcApp/Register.tsx), we import them [here](https://github.com/InseeFrLab/onyxia-ui/blob/3bf18aa82b198fc6ba7998c30abf0a9ae54a58b1/src/app/components/KcApp/KcApp.tsx#L9-L10) and use them [here](https://github.com/InseeFrLab/onyxia-ui/blob/3bf18aa82b198fc6ba7998c30abf0a9ae54a58b1/src/app/components/KcApp/KcApp.tsx#L113-L114).
|
||||||
|
We don't want to bother, however, customizing `login-reset-password.ftl`. We are fine using the component from [the default theme](https://github.com/InseeFrLab/onyxia-ui/blob/3bf18aa82b198fc6ba7998c30abf0a9ae54a58b1/src/app/components/KcApp/KcApp.tsx#L13) with just some [CSS customization](https://github.com/InseeFrLab/onyxia-ui/blob/3bf18aa82b198fc6ba7998c30abf0a9ae54a58b1/src/app/components/KcApp/KcApp.tsx#L103-L110).
|
||||||
|
|
||||||
|
WARNING: If you chose to go this way use:
|
||||||
|
```json
|
||||||
|
"dependencies": {
|
||||||
|
"keycloakify": "~X.Y.Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
in your `package.json` instead of `^X.Y.Z`. A minor update of Keycloakify might break your app.
|
||||||
|
|
||||||
### Hot reload
|
### Hot reload
|
||||||
|
|
||||||
By default, in order to see your changes you will have to wait for
|
Rebuild the theme each time you make a change to see the result is not practical.
|
||||||
`yarn build` to complete which can takes sevrall minute.
|
|
||||||
|
|
||||||
If you want to test your login screens outside of Keycloak, in [storybook](https://storybook.js.org/)
|
If you want to test your login screens outside of Keycloak, in [storybook](https://storybook.js.org/)
|
||||||
for example you can use `kcContextMocks`.
|
for example you can use `kcContextMocks`.
|
||||||
|
|
||||||
@ -131,7 +231,6 @@ import {
|
|||||||
} from "keycloakify";
|
} from "keycloakify";
|
||||||
|
|
||||||
reactDom.render(
|
reactDom.render(
|
||||||
kcContext !== undefined ?
|
|
||||||
<KcApp
|
<KcApp
|
||||||
kcContext={kcContextMocks.kcLoginContext}
|
kcContext={kcContextMocks.kcLoginContext}
|
||||||
{...defaultKcProps}
|
{...defaultKcProps}
|
||||||
@ -140,64 +239,150 @@ reactDom.render(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
then `yarn start` ...
|
Then `yarn start`, you will see your login page.
|
||||||
|
|
||||||
|
Checkout [this concrete example](https://github.com/garronej/keycloakify-demo-app/blob/main/src/index.tsx)
|
||||||
|
|
||||||
*NOTE: keycloak-react-theming was renamed keycloakify since this video was recorded*
|
## Enable loading in a blink of an eye of login pages ⚡ (--external-assets)
|
||||||
[](https://youtu.be/xTz0Rj7i2v8)
|
|
||||||
# How to implement context persistance
|
|
||||||
|
|
||||||
If you want dark mode preference, language and others users preferences
|
By default the theme generated is standalone. Meaning that when your users
|
||||||
to persist within the page served by keycloak here are the methods you can
|
reach the login pages all scripts, images and stylesheet are downloaded from the Keycloak server.
|
||||||
adopt.
|
If you are specifically building a theme to integrate with an app or a website that allows users
|
||||||
|
to first browse unauthenticated before logging in, you will get a significant
|
||||||
|
performance boost if you jump through those hoops:
|
||||||
|
|
||||||
## If your keycloak is a subdomain of your app.
|
- Provide the url of your app in the `homepage` field of package.json. [ex](https://github.com/garronej/keycloakify-demo-app/blob/7847cc70ef374ab26a6cc7953461cf25603e9a6d/package.json#L2)
|
||||||
|
- Build the theme using `npx build-keycloak-theme --external-assets` [ex](https://github.com/garronej/keycloakify-demo-app/blob/7847cc70ef374ab26a6cc7953461cf25603e9a6d/.github/workflows/ci.yaml#L21)
|
||||||
|
- Enable [long-term assets caching](https://create-react-app.dev/docs/production-build/#static-file-caching) on the server hosting your app.
|
||||||
|
- Make sure not to build your app and the keycloak theme separately
|
||||||
|
and remember to update the Keycloak theme every time you update your app.
|
||||||
|
- Be mindful that if your app is down your login pages are down as well.
|
||||||
|
|
||||||
E.g: Your app url is `my-app.com` and your keycloak url is `auth.my-app.com`.
|
Checkout a complete setup [here](https://github.com/garronej/keycloakify-demo-app#about-keycloakify)
|
||||||
|
|
||||||
In this case there is a very straightforward approach and it is to use [`powerhooks/useGlobalState`](https://github.com/garronej/powerhooks).
|
# Support for Terms and conditions
|
||||||
Instead of `{ "persistance": "localStorage" }` use `{ "persistance": "cookie" }`.
|
|
||||||
|
|
||||||
## Else
|
[Many organizations have a requirement that when a new user logs in for the first time, they need to agree to the terms and conditions of the website.](https://www.keycloak.org/docs/4.8/server_admin/#terms-and-conditions).
|
||||||
|
|
||||||
You will have to use URL parameters to passes states when you redirect to
|
First you need to enable the required action on the Keycloak server admin console:
|
||||||
the login page.
|

|
||||||
|
|
||||||
TOTO: Provide a clean way, as abstracted as possible, way to do that.
|
Then to load your own therms of services using [like this](https://github.com/garronej/keycloakify-demo-app/blob/8168c928a66605f2464f9bd28a4dc85fb0a231f9/src/index.tsx#L42-L66).
|
||||||
|
|
||||||
|
# Some pages still have the default theme. Why?
|
||||||
|
|
||||||
|
This project only support the most common user facing pages of Keycloak login.
|
||||||
|
[Here](https://user-images.githubusercontent.com/6702424/116787906-227fe700-aaa7-11eb-92ee-22e7673717c2.png) is the complete list of pages (you get them after running `yarn test`)
|
||||||
|
and [here](https://github.com/InseeFrLab/keycloakify/tree/main/src/lib/components) are the pages currently implemented by this module.
|
||||||
|
If you need to customize pages that are not supported yet you can submit an issue about it and wait for me get it implemented.
|
||||||
|
If you can't wait, PR are welcome! [Here](https://github.com/InseeFrLab/keycloakify/commit/0163459ad6b1ad0afcc34fae5f3cc28dbcf8b4a7) is the commit that adds support
|
||||||
|
for the `login-otp.ftl` page. You can use it as a model for implementing other pages.
|
||||||
|
|
||||||
# GitHub Actions
|
# GitHub Actions
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[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
|
|
||||||
|
|
||||||
This tools assumes you are bundling your app with Webpack (tested with 4.44.2) .
|
**All this is defaults with [`create-react-app`](https://create-react-app.dev)** (tested with 4.0.3)
|
||||||
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.
|
|
||||||
|
|
||||||
**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 (but you can build the theme in the CI)
|
||||||
|
- For testing the theme in a local Keycloak container (which is not mandatory for development):
|
||||||
|
`rm`, `mkdir`, `wget`, `unzip` are assumed to be available and `docker` up and running.
|
||||||
|
# Limitations
|
||||||
|
## `process.env.PUBLIC_URL` not supported.
|
||||||
|
|
||||||
- For building the theme: `mvn` (Maven) must be installed
|
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).
|
||||||
- For development, (testing the theme in a local container ): `rm`, `mkdir`, `wget`, `unzip` are assumed to be available
|
(This isn't recommended anyway).
|
||||||
and `docker` up and running.
|
|
||||||
|
|
||||||
NOTE: This build tool has only be tested on MacOS.
|
|
||||||
|
|
||||||
# API Reference
|
|
||||||
|
|
||||||
## The build tool
|
## `@font-face` importing fonts from the `src/` dir
|
||||||
|
|
||||||
Part of the lib that runs with node, at build time.
|
If you are building the theme with [--external-assets](#enable-loading-in-a-blink-of-a-eye-of-login-pages-)
|
||||||
|
this limitation doesn't apply, you can import fonts however you see fit.
|
||||||
|
|
||||||
- `npx build-keycloak-theme`: Builds the theme, the CWD is assumed to be the root of your react project.
|
### Example of setup that **won't** work
|
||||||
- `npx download-sample-keycloak-themes`: Downloads the keycloak default themes (for development purposes)
|
|
||||||
|
|
||||||
## The fronted lib ( imported into your react app )
|
- 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.
|
||||||
|
|
||||||
Part of the lib that you import in your react project and runs on the browser.
|
### Possible workarounds
|
||||||
|
|
||||||
**TODO**
|
- Use [`--external-assets`](#enable-loading-in-a-blink-of-a-eye-of-login-pages-).
|
||||||
|
- 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](https://github.com/InseeFrLab/onyxia-ui/blob/0e3a04610cfe872ca71dad59e05ced8f785dee4b/public/index.html#L6-L51).
|
||||||
|
- You can also [use non relative 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
|
||||||
|
you don't want it to be reset to default when the user gets redirected to
|
||||||
|
the login or register pages.
|
||||||
|
|
||||||
|
Same goes for the dark mode, you don't want, if the user had it enabled
|
||||||
|
to show the login page with light themes.
|
||||||
|
|
||||||
|
The problem is that you are probably using `localStorage` to persist theses values across
|
||||||
|
reload but, as the Keycloak pages are not served on the same domain that the rest of your
|
||||||
|
app you won't be able to carry over states using `localStorage`.
|
||||||
|
|
||||||
|
The only reliable solution is to inject parameters into the URL before
|
||||||
|
redirecting to Keycloak. We integrate with
|
||||||
|
[`keycloak-js`](https://github.com/keycloak/keycloak-documentation/blob/master/securing_apps/topics/oidc/javascript-adapter.adoc),
|
||||||
|
by providing you a way to tell `keycloak-js` that you would like to inject
|
||||||
|
some search parameters before redirecting.
|
||||||
|
|
||||||
|
The method also works with [`@react-keycloak/web`](https://www.npmjs.com/package/@react-keycloak/web) (use the `initOptions`).
|
||||||
|
|
||||||
|
You can implement your own mechanism to pass the states in the URL and
|
||||||
|
restore it on the other side but we recommend using `powerhooks/useGlobalState`
|
||||||
|
from the library [`powerhooks`](https://www.powerhooks.dev) that provide an elegant
|
||||||
|
way to handle states such as `isDarkModeEnabled` or `selectedLanguage`.
|
||||||
|
|
||||||
|
Let's modify [the example](https://github.com/keycloak/keycloak-documentation/blob/master/securing_apps/topics/oidc/javascript-adapter.adoc) from the official `keycloak-js` documentation to
|
||||||
|
enables the states of `useGlobalStates` to be injected in the URL before redirecting.
|
||||||
|
Note that the states are automatically restored on the other side by `powerhooks`
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import keycloak_js from "keycloak-js";
|
||||||
|
import { injectGlobalStatesInSearchParams } from "powerhooks/useGlobalState";
|
||||||
|
import { createKeycloakAdapter } from "keycloakify";
|
||||||
|
|
||||||
|
//...
|
||||||
|
|
||||||
|
const keycloakInstance = keycloak_js({
|
||||||
|
"url": "http://keycloak-server/auth",
|
||||||
|
"realm": "myrealm",
|
||||||
|
"clientId": "myapp"
|
||||||
|
});
|
||||||
|
|
||||||
|
keycloakInstance.init({
|
||||||
|
"onLoad": 'check-sso',
|
||||||
|
"silentCheckSsoRedirectUri": window.location.origin + "/silent-check-sso.html",
|
||||||
|
"adapter": createKeycloakAdapter({
|
||||||
|
"transformUrlBeforeRedirect": injectGlobalStatesInSearchParams,
|
||||||
|
keycloakInstance
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
//...
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
[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`.
|
||||||
|
|
||||||
|
# Kickstart video
|
||||||
|
|
||||||
|
*NOTE: keycloak-react-theming was renamed keycloakify since this video was recorded*
|
||||||
|
[](https://youtu.be/xTz0Rj7i2v8)
|
||||||
|
|
||||||
|
# Email domain whitelist
|
||||||
|
|
||||||
|
If you want to restrict the emails domain that can register, you can use [this plugin](https://github.com/micedre/keycloak-mail-whitelisting)
|
||||||
|
and `kcRegisterContext["authorizedMailDomains"]` to validate on.
|
||||||
|
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "0.2.5",
|
"version": "1.1.1",
|
||||||
"description": "Keycloak theme generator for Reacts app",
|
"description": "Keycloak theme generator for Reacts app",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -13,10 +13,8 @@
|
|||||||
"build": "yarn clean && tsc && yarn grant-exec-perms && yarn copy-files",
|
"build": "yarn clean && tsc && yarn grant-exec-perms && yarn copy-files",
|
||||||
"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",
|
||||||
"enable_short_import_path": "yarn build && denoify_enable_short_npm_import_path",
|
|
||||||
"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",
|
||||||
@ -45,19 +43,19 @@
|
|||||||
"@types/node": "^10.0.0",
|
"@types/node": "^10.0.0",
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.0",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
"denoify": "^0.6.5",
|
|
||||||
"properties-parser": "^0.3.1",
|
"properties-parser": "^0.3.1",
|
||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"typescript": "^4.1.5"
|
"typescript": "^4.2.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cheerio": "^1.0.0-rc.5",
|
"cheerio": "^1.0.0-rc.5",
|
||||||
"evt": "2.0.0-beta.15",
|
"evt": "2.0.0-beta.15",
|
||||||
"minimal-polyfills": "^2.1.6",
|
"minimal-polyfills": "^2.1.6",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"powerhooks": "^0.0.21",
|
"powerhooks": "^0.1.0",
|
||||||
|
"react-markdown": "^5.0.3",
|
||||||
"scripting-tools": "^0.19.13",
|
"scripting-tools": "^0.19.13",
|
||||||
"tss-react": "^0.0.11"
|
"tss-react": "^0.0.12"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
113
src/bin/build-keycloak-theme/build-keycloak-theme.ts
Normal file
113
src/bin/build-keycloak-theme/build-keycloak-theme.ts
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources";
|
||||||
|
import { generateJavaStackFiles } from "./generateJavaStackFiles";
|
||||||
|
import type { ParsedPackageJson } from "./generateJavaStackFiles";
|
||||||
|
import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path";
|
||||||
|
import * as child_process from "child_process";
|
||||||
|
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
|
||||||
|
import { URL } from "url";
|
||||||
|
|
||||||
|
|
||||||
|
const reactProjectDirPath = process.cwd();
|
||||||
|
|
||||||
|
const doUseExternalAssets = process.argv[2]?.toLowerCase() === "--external-assets";
|
||||||
|
|
||||||
|
const parsedPackageJson: ParsedPackageJson = require(pathJoin(reactProjectDirPath, "package.json"));
|
||||||
|
|
||||||
|
export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak");
|
||||||
|
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
|
||||||
|
console.log("🔏 Building the keycloak theme...⌚");
|
||||||
|
|
||||||
|
generateKeycloakThemeResources({
|
||||||
|
keycloakThemeBuildingDirPath,
|
||||||
|
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
||||||
|
"themeName": parsedPackageJson.name,
|
||||||
|
...(() => {
|
||||||
|
|
||||||
|
const url = (() => {
|
||||||
|
|
||||||
|
const { homepage } = parsedPackageJson;
|
||||||
|
|
||||||
|
return homepage === undefined ?
|
||||||
|
undefined :
|
||||||
|
new URL(homepage);
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
return {
|
||||||
|
"urlPathname":
|
||||||
|
url === undefined ?
|
||||||
|
"/" :
|
||||||
|
url.pathname.replace(/([^/])$/, "$1/"),
|
||||||
|
"urlOrigin": !doUseExternalAssets ? undefined : (() => {
|
||||||
|
|
||||||
|
if (url === undefined) {
|
||||||
|
console.error("ERROR: You must specify 'homepage' in your package.json");
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.origin;
|
||||||
|
|
||||||
|
})()
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
|
||||||
|
const { jarFilePath } = generateJavaStackFiles({
|
||||||
|
parsedPackageJson,
|
||||||
|
keycloakThemeBuildingDirPath
|
||||||
|
});
|
||||||
|
|
||||||
|
child_process.execSync(
|
||||||
|
"mvn package",
|
||||||
|
{ "cwd": keycloakThemeBuildingDirPath }
|
||||||
|
);
|
||||||
|
|
||||||
|
generateDebugFiles({
|
||||||
|
keycloakThemeBuildingDirPath,
|
||||||
|
"packageJsonName": parsedPackageJson.name
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log([
|
||||||
|
'',
|
||||||
|
`✅ Your keycloak theme has been generated and bundled into ./${pathRelative(reactProjectDirPath, jarFilePath)} 🚀`,
|
||||||
|
`It is to be placed in "/opt/jboss/keycloak/standalone/deployments" in the container running a jboss/keycloak Docker image. (Tested with 11.0.3)`,
|
||||||
|
'',
|
||||||
|
'Using Helm (https://github.com/codecentric/helm-charts), edit to reflect:',
|
||||||
|
'',
|
||||||
|
'value.yaml: ',
|
||||||
|
' extraInitContainers: |',
|
||||||
|
' - name: realm-ext-provider',
|
||||||
|
' image: curlimages/curl',
|
||||||
|
' imagePullPolicy: IfNotPresent',
|
||||||
|
' command:',
|
||||||
|
' - sh',
|
||||||
|
' args:',
|
||||||
|
' - -c',
|
||||||
|
` - curl -L -f -S -o /extensions/${pathBasename(jarFilePath)} https://AN.URL.FOR/${pathBasename(jarFilePath)}`,
|
||||||
|
' volumeMounts:',
|
||||||
|
' - name: extensions',
|
||||||
|
' mountPath: /extensions',
|
||||||
|
' ',
|
||||||
|
' extraVolumeMounts: |',
|
||||||
|
' - name: extensions',
|
||||||
|
' mountPath: /opt/jboss/keycloak/standalone/deployments',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'To test your theme locally, with hot reloading, you can spin up a Keycloak container image with the theme loaded by running:',
|
||||||
|
'',
|
||||||
|
`👉 $ ./${pathRelative(reactProjectDirPath, pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename))} 👈`,
|
||||||
|
'',
|
||||||
|
'To enable the theme within keycloak log into the admin console ( 👉 http://localhost:8080 username: admin, password: admin 👈), create a realm (called "myrealm" for example),',
|
||||||
|
`go to your realm settings, click on the theme tab then select ${parsedPackageJson.name}.`,
|
||||||
|
`More details: https://www.keycloak.org/getting-started/getting-started-docker`,
|
||||||
|
'',
|
||||||
|
'Once your container is up and configured 👉 http://localhost:8080/auth/realms/myrealm/account 👈',
|
||||||
|
'',
|
||||||
|
].join("\n"));
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { join as pathJoin, dirname as pathDirname, basename as pathBasename } from "path";
|
||||||
|
|
||||||
|
export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh";
|
||||||
|
|
||||||
|
/** Files for being able to run a hot reload keycloak container */
|
||||||
|
export function generateDebugFiles(
|
||||||
|
params: {
|
||||||
|
packageJsonName: string;
|
||||||
|
keycloakThemeBuildingDirPath: string;
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
|
||||||
|
const { packageJsonName, keycloakThemeBuildingDirPath } = params;
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
pathJoin(keycloakThemeBuildingDirPath, "Dockerfile"),
|
||||||
|
Buffer.from(
|
||||||
|
[
|
||||||
|
"FROM jboss/keycloak:11.0.3",
|
||||||
|
"",
|
||||||
|
"USER root",
|
||||||
|
"",
|
||||||
|
"WORKDIR /",
|
||||||
|
"",
|
||||||
|
"ADD configuration /opt/jboss/keycloak/standalone/configuration/",
|
||||||
|
"",
|
||||||
|
'ENTRYPOINT [ "/opt/jboss/tools/docker-entrypoint.sh" ]',
|
||||||
|
].join("\n"),
|
||||||
|
"utf8"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const dockerImage = `${packageJsonName}/keycloak-hot-reload`;
|
||||||
|
const containerName = "keycloak-testing-container";
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename),
|
||||||
|
Buffer.from(
|
||||||
|
[
|
||||||
|
"#!/bin/bash",
|
||||||
|
"",
|
||||||
|
`cd ${keycloakThemeBuildingDirPath}`,
|
||||||
|
"",
|
||||||
|
`docker rm ${containerName} || true`,
|
||||||
|
"",
|
||||||
|
`docker build . -t ${dockerImage}`,
|
||||||
|
"",
|
||||||
|
"docker run \\",
|
||||||
|
" -p 8080:8080 \\",
|
||||||
|
` --name ${containerName} \\`,
|
||||||
|
" -e KEYCLOAK_USER=admin \\",
|
||||||
|
" -e KEYCLOAK_PASSWORD=admin \\",
|
||||||
|
` -v ${pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", packageJsonName)
|
||||||
|
}:/opt/jboss/keycloak/themes/${packageJsonName}:rw \\`,
|
||||||
|
` -it ${dockerImage}:latest`,
|
||||||
|
""
|
||||||
|
].join("\n"),
|
||||||
|
"utf8"
|
||||||
|
),
|
||||||
|
{ "mode": 0o755 }
|
||||||
|
);
|
||||||
|
|
||||||
|
const standaloneHaFilePath = pathJoin(keycloakThemeBuildingDirPath, "configuration", "standalone-ha.xml");
|
||||||
|
|
||||||
|
try { fs.mkdirSync(pathDirname(standaloneHaFilePath)); } catch { }
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
standaloneHaFilePath,
|
||||||
|
fs.readFileSync(pathJoin(__dirname, pathBasename(standaloneHaFilePath)))
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
@ -1,74 +1 @@
|
|||||||
|
export * from "./generateDebugFiles";
|
||||||
import * as fs from "fs";
|
|
||||||
import { join as pathJoin, dirname as pathDirname, basename as pathBasename } from "path";
|
|
||||||
|
|
||||||
export const containerLaunchScriptBasename = "start_keycloak_testing_container.sh";
|
|
||||||
|
|
||||||
/** Files for being able to run a hot reload keycloak container */
|
|
||||||
export function generateDebugFiles(
|
|
||||||
params: {
|
|
||||||
packageJsonName: string;
|
|
||||||
keycloakThemeBuildingDirPath: string;
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
|
|
||||||
const { packageJsonName, keycloakThemeBuildingDirPath } = params;
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
pathJoin(keycloakThemeBuildingDirPath, "Dockerfile"),
|
|
||||||
Buffer.from(
|
|
||||||
[
|
|
||||||
"FROM jboss/keycloak:11.0.3",
|
|
||||||
"",
|
|
||||||
"USER root",
|
|
||||||
"",
|
|
||||||
"WORKDIR /",
|
|
||||||
"",
|
|
||||||
"ADD configuration /opt/jboss/keycloak/standalone/configuration/",
|
|
||||||
"",
|
|
||||||
'ENTRYPOINT [ "/opt/jboss/tools/docker-entrypoint.sh" ]',
|
|
||||||
].join("\n"),
|
|
||||||
"utf8"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const dockerImage = `${packageJsonName}/keycloak-hot-reload`;
|
|
||||||
const containerName = "keycloak-testing-container";
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename),
|
|
||||||
Buffer.from(
|
|
||||||
[
|
|
||||||
"#!/bin/bash",
|
|
||||||
"",
|
|
||||||
`cd ${keycloakThemeBuildingDirPath}`,
|
|
||||||
"",
|
|
||||||
`docker rm ${containerName} || true`,
|
|
||||||
"",
|
|
||||||
`docker build . -t ${dockerImage}`,
|
|
||||||
"",
|
|
||||||
"docker run \\",
|
|
||||||
" -p 8080:8080 \\",
|
|
||||||
` --name ${containerName} \\`,
|
|
||||||
" -e KEYCLOAK_USER=admin \\",
|
|
||||||
" -e KEYCLOAK_PASSWORD=admin \\",
|
|
||||||
` -v ${pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", packageJsonName)
|
|
||||||
}:/opt/jboss/keycloak/themes/${packageJsonName}:rw \\`,
|
|
||||||
` -it ${dockerImage}:latest`,
|
|
||||||
""
|
|
||||||
].join("\n"),
|
|
||||||
"utf8"
|
|
||||||
),
|
|
||||||
{ "mode": 0o755 }
|
|
||||||
);
|
|
||||||
|
|
||||||
const standaloneHaFilePath = pathJoin(keycloakThemeBuildingDirPath, "configuration", "standalone-ha.xml");
|
|
||||||
|
|
||||||
try { fs.mkdirSync(pathDirname(standaloneHaFilePath)); } catch { }
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
standaloneHaFilePath,
|
|
||||||
fs.readFileSync(pathJoin(__dirname, pathBasename(standaloneHaFilePath)))
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
263
src/bin/build-keycloak-theme/generateFtl/common.ftl
Normal file
263
src/bin/build-keycloak-theme/generateFtl/common.ftl
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
<script>const _=
|
||||||
|
{
|
||||||
|
"url": {
|
||||||
|
"loginAction": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${url.loginAction?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"resourcesPath": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${url.resourcesPath?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"resourcesCommonPath": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${url.resourcesCommonPath?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"loginRestartFlowUrl": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${url.loginRestartFlowUrl?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"loginUrl": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${url.loginUrl?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
},
|
||||||
|
"realm": {
|
||||||
|
"displayName": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${realm.displayName!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"displayNameHtml": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${realm.displayNameHtml!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"internationalizationEnabled": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.internationalizationEnabled?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"registrationEmailAsUsername": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.registrationEmailAsUsername?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
},
|
||||||
|
"locale": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if realm.internationalizationEnabled>
|
||||||
|
|
||||||
|
return {
|
||||||
|
"supported": (function(){
|
||||||
|
|
||||||
|
var out= [];
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#list locale.supported as lng>
|
||||||
|
out.push({
|
||||||
|
"url": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${lng.url?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"label": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${lng.label}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"languageTag": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${lng.languageTag}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
</#list>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"current": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${locale.current}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"auth": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if auth?has_content>
|
||||||
|
|
||||||
|
var out= {
|
||||||
|
"showUsername": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return ${auth.showUsername()?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"showResetCredentials": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return ${auth.showResetCredentials()?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"showTryAnotherWayLink": (function(){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return ${auth.showTryAnotherWayLink()?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if auth.showUsername() && !auth.showResetCredentials()>
|
||||||
|
Object.assign(
|
||||||
|
out,
|
||||||
|
{
|
||||||
|
"attemptedUsername": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${auth.attemptedUsername}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"scripts": (function(){
|
||||||
|
|
||||||
|
var out = [];
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if scripts??>
|
||||||
|
<#attempt>
|
||||||
|
<#list scripts as script>
|
||||||
|
out.push((function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${script}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})());
|
||||||
|
</#list>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"message": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if message?has_content>
|
||||||
|
|
||||||
|
return {
|
||||||
|
"type": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${message.type}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"summary": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return String.htmlUnescape("${message.summary}");
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"isAppInitiatedAction": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if isAppInitiatedAction??>
|
||||||
|
return true;
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
</script>
|
@ -2,13 +2,21 @@
|
|||||||
{
|
{
|
||||||
"client": (function (){
|
"client": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if client??>
|
<#if client??>
|
||||||
return {
|
return {
|
||||||
"baseUrl": "${(client.baseUrl!'')?no_esc}" || undefined
|
"baseUrl": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${(client.baseUrl!'')?no_esc}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
};
|
};
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
return undefined;
|
</#attempt>
|
||||||
|
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
193
src/bin/build-keycloak-theme/generateFtl/generateFtl.ts
Normal file
193
src/bin/build-keycloak-theme/generateFtl/generateFtl.ts
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import cheerio from "cheerio";
|
||||||
|
import {
|
||||||
|
replaceImportsFromStaticInJsCode,
|
||||||
|
replaceImportsInInlineCssCode,
|
||||||
|
generateCssCodeToDefineGlobals
|
||||||
|
} from "../replaceImportFromStatic";
|
||||||
|
import fs from "fs";
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
||||||
|
import { ftlValuesGlobalName } from "../ftlValuesGlobalName";
|
||||||
|
|
||||||
|
export const pageIds = [
|
||||||
|
"login.ftl", "register.ftl", "info.ftl",
|
||||||
|
"error.ftl", "login-reset-password.ftl",
|
||||||
|
"login-verify-email.ftl", "terms.ftl",
|
||||||
|
"login-otp.ftl", "login-update-profile.ftl",
|
||||||
|
"login-idp-link-confirm.ftl"
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type PageId = typeof pageIds[number];
|
||||||
|
|
||||||
|
function loadAdjacentFile(fileBasename: string) {
|
||||||
|
return fs.readFileSync(pathJoin(__dirname, fileBasename))
|
||||||
|
.toString("utf8");
|
||||||
|
};
|
||||||
|
|
||||||
|
function loadFtlFile(ftlFileBasename: PageId | "common.ftl") {
|
||||||
|
try {
|
||||||
|
|
||||||
|
return loadAdjacentFile(ftlFileBasename)
|
||||||
|
.match(/^<script>const _=((?:.|\n)+)<\/script>[\n]?$/)![1];
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function generateFtlFilesCodeFactory(
|
||||||
|
params: {
|
||||||
|
cssGlobalsToDefine: Record<string, string>;
|
||||||
|
indexHtmlCode: string;
|
||||||
|
urlPathname: string;
|
||||||
|
urlOrigin: undefined | string;
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
|
||||||
|
const { cssGlobalsToDefine, indexHtmlCode, urlPathname, urlOrigin } = params;
|
||||||
|
|
||||||
|
const $ = cheerio.load(indexHtmlCode);
|
||||||
|
|
||||||
|
$("script:not([src])").each((...[, element]) => {
|
||||||
|
|
||||||
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
||||||
|
"jsCode": $(element).html()!,
|
||||||
|
urlOrigin
|
||||||
|
});
|
||||||
|
|
||||||
|
$(element).text(fixedJsCode);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$("style").each((...[, element]) => {
|
||||||
|
|
||||||
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||||
|
"cssCode": $(element).html()!,
|
||||||
|
"urlPathname": params.urlPathname,
|
||||||
|
urlOrigin
|
||||||
|
});
|
||||||
|
|
||||||
|
$(element).text(fixedCssCode);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
([
|
||||||
|
["link", "href"],
|
||||||
|
["script", "src"],
|
||||||
|
] as const).forEach(([selector, attrName]) =>
|
||||||
|
$(selector).each((...[, element]) => {
|
||||||
|
|
||||||
|
const href = $(element).attr(attrName);
|
||||||
|
|
||||||
|
if (href === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(element).attr(
|
||||||
|
attrName,
|
||||||
|
urlOrigin !== undefined ?
|
||||||
|
href.replace(/^\//, `${urlOrigin}/`) :
|
||||||
|
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.
|
||||||
|
const ftlCommonPlaceholders = {
|
||||||
|
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }': loadFtlFile("common.ftl"),
|
||||||
|
'<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->':
|
||||||
|
[
|
||||||
|
'<#if scripts??>',
|
||||||
|
' <#list scripts as script>',
|
||||||
|
' <script src="${script}" type="text/javascript"></script>',
|
||||||
|
' </#list>',
|
||||||
|
'</#if>'
|
||||||
|
].join("\n")
|
||||||
|
};
|
||||||
|
|
||||||
|
const pageSpecificCodePlaceholder = "<!-- dIddLqMeOedErIdLsPdNdI9dSl42sw -->";
|
||||||
|
|
||||||
|
$("head").prepend(
|
||||||
|
[
|
||||||
|
...(Object.keys(cssGlobalsToDefine).length === 0 ? [] : [
|
||||||
|
'',
|
||||||
|
'<style>',
|
||||||
|
generateCssCodeToDefineGlobals({
|
||||||
|
cssGlobalsToDefine,
|
||||||
|
urlPathname
|
||||||
|
}).cssCodeToPrependInHead,
|
||||||
|
'</style>',
|
||||||
|
''
|
||||||
|
]),
|
||||||
|
...["Object.deepAssign.js", "String.htmlUnescape.js"].map(
|
||||||
|
fileBasename => [
|
||||||
|
"<script>",
|
||||||
|
loadAdjacentFile(fileBasename),
|
||||||
|
"</script>"
|
||||||
|
].join("\n")
|
||||||
|
),
|
||||||
|
'<script>',
|
||||||
|
` window.${ftlValuesGlobalName}= Object.assign(`,
|
||||||
|
` {},`,
|
||||||
|
` ${objectKeys(ftlCommonPlaceholders)[0]}`,
|
||||||
|
' );',
|
||||||
|
'</script>',
|
||||||
|
'',
|
||||||
|
pageSpecificCodePlaceholder,
|
||||||
|
'',
|
||||||
|
objectKeys(ftlCommonPlaceholders)[1]
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const partiallyFixedIndexHtmlCode = $.html();
|
||||||
|
|
||||||
|
function generateFtlFilesCode(
|
||||||
|
params: {
|
||||||
|
pageId: PageId;
|
||||||
|
}
|
||||||
|
): { ftlCode: string; } {
|
||||||
|
|
||||||
|
const { pageId } = params;
|
||||||
|
|
||||||
|
const $ = cheerio.load(partiallyFixedIndexHtmlCode);
|
||||||
|
|
||||||
|
const ftlPlaceholders = {
|
||||||
|
'{ "x": "kxOlLqMeOed9sdLdIdOxd444" }': loadFtlFile(pageId),
|
||||||
|
...ftlCommonPlaceholders
|
||||||
|
};
|
||||||
|
|
||||||
|
let ftlCode = $.html()
|
||||||
|
.replace(
|
||||||
|
pageSpecificCodePlaceholder,
|
||||||
|
[
|
||||||
|
'<script>',
|
||||||
|
` Object.deepAssign(`,
|
||||||
|
` window.${ftlValuesGlobalName},`,
|
||||||
|
` { "pageId": "${pageId}" }`,
|
||||||
|
' );',
|
||||||
|
` Object.deepAssign(`,
|
||||||
|
` window.${ftlValuesGlobalName},`,
|
||||||
|
` ${objectKeys(ftlPlaceholders)[0]}`,
|
||||||
|
' );',
|
||||||
|
'</script>'
|
||||||
|
].join("\n")
|
||||||
|
);
|
||||||
|
|
||||||
|
objectKeys(ftlPlaceholders)
|
||||||
|
.forEach(id => ftlCode = ftlCode.replace(id, ftlPlaceholders[id]));
|
||||||
|
|
||||||
|
return { ftlCode };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return { generateFtlFilesCode };
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,162 +1 @@
|
|||||||
|
export * from "./generateFtl";
|
||||||
|
|
||||||
import cheerio from "cheerio";
|
|
||||||
import {
|
|
||||||
replaceImportFromStaticInJsCode,
|
|
||||||
generateCssCodeToDefineGlobals
|
|
||||||
} from "../replaceImportFromStatic";
|
|
||||||
import fs from "fs";
|
|
||||||
import { join as pathJoin } from "path";
|
|
||||||
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
|
||||||
|
|
||||||
export const pageIds = ["login.ftl", "register.ftl", "info.ftl", "error.ftl", "login-reset-password.ftl", "login-verify-email.ftl"] as const;
|
|
||||||
|
|
||||||
export type PageId = typeof pageIds[number];
|
|
||||||
|
|
||||||
function loadAdjacentFile(fileBasename: string){
|
|
||||||
return fs.readFileSync(pathJoin(__dirname, fileBasename))
|
|
||||||
.toString("utf8");
|
|
||||||
};
|
|
||||||
|
|
||||||
function loadFtlFile(ftlFileBasename: PageId | "template.ftl") {
|
|
||||||
try {
|
|
||||||
|
|
||||||
return loadAdjacentFile(ftlFileBasename)
|
|
||||||
.match(/^<script>const _=((?:.|\n)+)<\/script>[\n]?$/)![1];
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateFtlFilesCodeFactory(
|
|
||||||
params: {
|
|
||||||
ftlValuesGlobalName: string;
|
|
||||||
cssGlobalsToDefine: Record<string, string>;
|
|
||||||
indexHtmlCode: string;
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
|
|
||||||
const { ftlValuesGlobalName, cssGlobalsToDefine, indexHtmlCode } = params;
|
|
||||||
|
|
||||||
const $ = cheerio.load(indexHtmlCode);
|
|
||||||
|
|
||||||
$("script:not([src])").each((...[, element]) => {
|
|
||||||
|
|
||||||
const { fixedJsCode } = replaceImportFromStaticInJsCode({
|
|
||||||
ftlValuesGlobalName,
|
|
||||||
"jsCode": $(element).html()!
|
|
||||||
});
|
|
||||||
|
|
||||||
$(element).text(fixedJsCode);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
([
|
|
||||||
["link", "href"],
|
|
||||||
["script", "src"],
|
|
||||||
] as const).forEach(([selector, attrName]) =>
|
|
||||||
$(selector).each((...[, element]) => {
|
|
||||||
|
|
||||||
const href = $(element).attr(attrName);
|
|
||||||
|
|
||||||
if (!href?.startsWith("/")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$(element).attr(attrName, "${url.resourcesPath}/build" + href);
|
|
||||||
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
|
||||||
const ftlCommonPlaceholders = {
|
|
||||||
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }': loadFtlFile("template.ftl"),
|
|
||||||
'<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->':
|
|
||||||
[
|
|
||||||
'<#if scripts??>',
|
|
||||||
' <#list scripts as script>',
|
|
||||||
' <script src="${script}" type="text/javascript"></script>',
|
|
||||||
' </#list>',
|
|
||||||
'</#if>'
|
|
||||||
].join("\n")
|
|
||||||
};
|
|
||||||
|
|
||||||
const pageSpecificCodePlaceholder = "<!-- dIddLqMeOedErIdLsPdNdI9dSl42sw -->";
|
|
||||||
|
|
||||||
$("head").prepend(
|
|
||||||
[
|
|
||||||
...(Object.keys(cssGlobalsToDefine).length === 0 ? [] : [
|
|
||||||
'',
|
|
||||||
'<style>',
|
|
||||||
generateCssCodeToDefineGlobals(
|
|
||||||
{ cssGlobalsToDefine }
|
|
||||||
).cssCodeToPrependInHead,
|
|
||||||
'</style>',
|
|
||||||
''
|
|
||||||
]),
|
|
||||||
...["Object.deepAssign.js", "String.htmlUnescape.js"].map(
|
|
||||||
fileBasename => [
|
|
||||||
"<script>",
|
|
||||||
loadAdjacentFile(fileBasename),
|
|
||||||
"</script>"
|
|
||||||
].join("\n")
|
|
||||||
),
|
|
||||||
'<script>',
|
|
||||||
` window.${ftlValuesGlobalName}= Object.assign(`,
|
|
||||||
` {},`,
|
|
||||||
` ${objectKeys(ftlCommonPlaceholders)[0]}`,
|
|
||||||
' );',
|
|
||||||
'</script>',
|
|
||||||
'',
|
|
||||||
pageSpecificCodePlaceholder,
|
|
||||||
'',
|
|
||||||
objectKeys(ftlCommonPlaceholders)[1]
|
|
||||||
].join("\n"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const partiallyFixedIndexHtmlCode = $.html();
|
|
||||||
|
|
||||||
function generateFtlFilesCode(
|
|
||||||
params: {
|
|
||||||
pageId: PageId;
|
|
||||||
}
|
|
||||||
): { ftlCode: string; } {
|
|
||||||
|
|
||||||
const { pageId } = params;
|
|
||||||
|
|
||||||
const $ = cheerio.load(partiallyFixedIndexHtmlCode);
|
|
||||||
|
|
||||||
const ftlPlaceholders = {
|
|
||||||
'{ "x": "kxOlLqMeOed9sdLdIdOxd444" }': loadFtlFile(pageId),
|
|
||||||
...ftlCommonPlaceholders
|
|
||||||
};
|
|
||||||
|
|
||||||
let ftlCode = $.html()
|
|
||||||
.replace(
|
|
||||||
pageSpecificCodePlaceholder,
|
|
||||||
[
|
|
||||||
'<script>',
|
|
||||||
` Object.deepAssign(`,
|
|
||||||
` window.${ftlValuesGlobalName},`,
|
|
||||||
` { "pageId": "${pageId}" }`,
|
|
||||||
' );',
|
|
||||||
` Object.deepAssign(`,
|
|
||||||
` window.${ftlValuesGlobalName},`,
|
|
||||||
` ${objectKeys(ftlPlaceholders)[0]}`,
|
|
||||||
' );',
|
|
||||||
'</script>'
|
|
||||||
].join("\n")
|
|
||||||
);
|
|
||||||
|
|
||||||
objectKeys(ftlPlaceholders)
|
|
||||||
.forEach(id => ftlCode = ftlCode.replace(id, ftlPlaceholders[id]));
|
|
||||||
|
|
||||||
return { ftlCode };
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return { generateFtlFilesCode };
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +1,82 @@
|
|||||||
<script>const _=
|
<script>const _=
|
||||||
{
|
{
|
||||||
"messageHeader": "${messageHeader!''}" || undefined,
|
"messageHeader": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messageHeader!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
"requiredActions": (function (){
|
"requiredActions": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if requiredActions??>
|
<#if requiredActions??>
|
||||||
|
|
||||||
var out =[];
|
var out =[];
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#list requiredActions>
|
<#list requiredActions>
|
||||||
|
<#attempt>
|
||||||
<#items as reqActionItem>
|
<#items as reqActionItem>
|
||||||
out.push("${reqActionItem}");
|
out.push((function (){
|
||||||
</#items></b>
|
|
||||||
|
<#attempt>
|
||||||
|
return "${reqActionItem}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})());
|
||||||
|
</#items>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
</#list>
|
</#list>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
<#else>
|
</#if>
|
||||||
|
<#recover>
|
||||||
return undefined;
|
</#attempt>
|
||||||
|
|
||||||
})(),
|
})(),
|
||||||
"skipLink": (function (){
|
"skipLink": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if skipLink??>
|
<#if skipLink??>
|
||||||
return true;
|
return true;
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
})(),
|
})(),
|
||||||
"pageRedirectUri": "${(pageRedirectUri!'')?no_esc}" || undefined,
|
"pageRedirectUri": (function (){
|
||||||
"actionUri": "${(actionUri!'')?no_esc}" || undefined,
|
|
||||||
|
<#attempt>
|
||||||
|
return "${(pageRedirectUri!'')?no_esc}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"actionUri": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${(actionUri!'')?no_esc}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
"client": {
|
"client": {
|
||||||
"baseUrl": "${(client.baseUrl!'')?no_esc}" || undefined
|
"baseUrl": (function(){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${(client.baseUrl!'')?no_esc}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
@ -0,0 +1,11 @@
|
|||||||
|
<script>const _=
|
||||||
|
{
|
||||||
|
"idpAlias": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${idpAlias}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
return "";
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
</script>
|
37
src/bin/build-keycloak-theme/generateFtl/login-otp.ftl
Normal file
37
src/bin/build-keycloak-theme/generateFtl/login-otp.ftl
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<script>const _=
|
||||||
|
{
|
||||||
|
"otpLogin": {
|
||||||
|
"userOtpCredentials": (function(){
|
||||||
|
|
||||||
|
var out = [];
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#list otpLogin.userOtpCredentials as otpCredential>
|
||||||
|
out.push({
|
||||||
|
"id": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${otpCredential.id}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"userLabel": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${otpCredential.userLabel}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
</#list>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -1,7 +1,14 @@
|
|||||||
<script>const _=
|
<script>const _=
|
||||||
{
|
{
|
||||||
"realm": {
|
"realm": {
|
||||||
"loginWithEmailAllowed": ${realm.loginWithEmailAllowed?c}
|
"loginWithEmailAllowed": (function (){
|
||||||
},
|
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.loginWithEmailAllowed?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
@ -0,0 +1,67 @@
|
|||||||
|
<script>const _=
|
||||||
|
{
|
||||||
|
"user": {
|
||||||
|
"editUsernameAllowed": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return ${user.editUsernameAllowed?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"username": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${user.username!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"emal": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${user.email!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"firstName": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${user.firstName!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"lastName": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${user.lastName!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})()
|
||||||
|
},
|
||||||
|
"messagesPerField": {
|
||||||
|
"printIfExists": function (key, x) {
|
||||||
|
switch(key){
|
||||||
|
case "username": return (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('username','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})();
|
||||||
|
case "email": return (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('email','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})();
|
||||||
|
case "firstName": return (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('firstName','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})();
|
||||||
|
case "lastName": return (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('lastName','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
@ -1,83 +1,160 @@
|
|||||||
<script>const _=
|
<script>const _=
|
||||||
{
|
{
|
||||||
"url": {
|
"url": {
|
||||||
"loginResetCredentialsUrl": "${url.loginResetCredentialsUrl?no_esc}",
|
"loginResetCredentialsUrl": (function (){
|
||||||
"registrationUrl": "${url.registrationUrl?no_esc}"
|
<#attempt>
|
||||||
|
return "${url.loginResetCredentialsUrl?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"registrationUrl": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${url.registrationUrl?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})()
|
||||||
},
|
},
|
||||||
"realm": {
|
"realm": {
|
||||||
"loginWithEmailAllowed": ${realm.loginWithEmailAllowed?c},
|
"loginWithEmailAllowed": (function(){
|
||||||
"rememberMe": ${realm.rememberMe?c},
|
<#attempt>
|
||||||
"password": ${realm.password?c},
|
return ${realm.loginWithEmailAllowed?c};
|
||||||
"resetPasswordAllowed": ${realm.resetPasswordAllowed?c},
|
<#recover>
|
||||||
"registrationAllowed": ${realm.registrationAllowed?c}
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"rememberMe": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.rememberMe?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"password": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.password?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"resetPasswordAllowed": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.resetPasswordAllowed?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"registrationAllowed": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return ${realm.registrationAllowed?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})()
|
||||||
},
|
},
|
||||||
"auth": (function (){
|
"auth": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if auth?has_content>
|
<#if auth?has_content>
|
||||||
|
|
||||||
var out= {
|
return {
|
||||||
"selectedCredential": "${auth.selectedCredential!''}" || undefined
|
"selectedCredential": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${auth.selectedCredential!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})()
|
||||||
};
|
};
|
||||||
|
|
||||||
return out;
|
|
||||||
|
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
return undefined;
|
</#attempt>
|
||||||
|
|
||||||
})(),
|
})(),
|
||||||
"social": {
|
"social": {
|
||||||
"displayInfo": ${social.displayInfo?c},
|
"displayInfo": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return ${social.displayInfo?c};
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
"providers": (()=>{
|
"providers": (()=>{
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if social.providers??>
|
<#if social.providers??>
|
||||||
|
|
||||||
var out= [];
|
var out= [];
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#list social.providers as p>
|
<#list social.providers as p>
|
||||||
out.push({
|
out.push({
|
||||||
"loginUrl": "${p.loginUrl?no_esc}",
|
"loginUrl": (function (){
|
||||||
"alias": "${p.alias}",
|
<#attempt>
|
||||||
"providerId": "${p.providerId}",
|
return "${p.loginUrl?no_esc}";
|
||||||
"displayName": "${p.displayName}"
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"alias": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${p.alias}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"providerId": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${p.providerId}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
|
"displayName": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${p.displayName}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})()
|
||||||
});
|
});
|
||||||
</#list>
|
</#list>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
return undefined;
|
</#attempt>
|
||||||
|
|
||||||
})()
|
})()
|
||||||
},
|
},
|
||||||
"usernameEditDisabled": (function () {
|
"usernameEditDisabled": (function () {
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if usernameEditDisabled??>
|
<#if usernameEditDisabled??>
|
||||||
return true;
|
return true;
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
})(),
|
})(),
|
||||||
"login": {
|
"login": {
|
||||||
"username": "${login.username!''}" || undefined,
|
"username": (function (){
|
||||||
|
<#attempt>
|
||||||
|
return "${login.username!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
})(),
|
||||||
"rememberMe": (function (){
|
"rememberMe": (function (){
|
||||||
|
<#attempt>
|
||||||
<#if login.rememberMe??>
|
<#if login.rememberMe??>
|
||||||
return true;
|
return true;
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
})()
|
})()
|
||||||
},
|
},
|
||||||
"registrationDisabled": (function (){
|
"registrationDisabled": (function (){
|
||||||
|
<#attempt>
|
||||||
<#if registrationDisabled??>
|
<#if registrationDisabled??>
|
||||||
return true;
|
return true;
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
@ -1,46 +1,189 @@
|
|||||||
<script>const _=
|
<script>const _=
|
||||||
{
|
{
|
||||||
"url": {
|
"url": {
|
||||||
"registrationAction": "${url.registrationAction?no_esc}"
|
"registrationAction": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${url.registrationAction?no_esc}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
},
|
},
|
||||||
"messagesPerField": {
|
"messagesPerField": {
|
||||||
"printIfExists": function (key, x) {
|
"printIfExists": function (key, x) {
|
||||||
switch(key){
|
switch(key){
|
||||||
case "userLabel": "${messagesPerField.printIfExists('userLabel','1')}" ? x : undefined;
|
case "userLabel": return (function (){
|
||||||
case "username": "${messagesPerField.printIfExists('username','1')}" ? x : undefined;
|
|
||||||
case "email": "${messagesPerField.printIfExists('email','1')}" ? x : undefined;
|
<#attempt>
|
||||||
case "firstName": "${messagesPerField.printIfExists('firstName','1')}" ? x : undefined;
|
return "${messagesPerField.printIfExists('userLabel','1')}" ? x : undefined;
|
||||||
case "lastName": "${messagesPerField.printIfExists('lastName','1')}" ? x : undefined;
|
<#recover>
|
||||||
case "password": "${messagesPerField.printIfExists('password','1')}" ? x : undefined;
|
</#attempt>
|
||||||
case "password-confirm": "${messagesPerField.printIfExists('password-confirm','1')}" ? x : undefined;
|
|
||||||
|
})();
|
||||||
|
case "username": return (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('username','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})();
|
||||||
|
case "email": return (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('email','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})();
|
||||||
|
case "firstName": return (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('firstName','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})();
|
||||||
|
case "lastName": return (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('lastName','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})();
|
||||||
|
case "password": return (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('password','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})();
|
||||||
|
case "password-confirm": return (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${messagesPerField.printIfExists('password-confirm','1')}" ? x : undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"register": {
|
"register": {
|
||||||
"formData": {
|
"formData": {
|
||||||
"firstName": "${register.formData.firstName!''}" || undefined,
|
"firstName": (function (){
|
||||||
"displayName": "${register.formData.displayName!''}" || undefined,
|
|
||||||
"lastName": "${register.formData.lastName!''}" || undefined,
|
<#attempt>
|
||||||
"email": "${register.formData.email!''}" || undefined,
|
return "${register.formData.firstName!''}" || undefined;
|
||||||
"username": "${register.formData.username!''}" || undefined
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"displayName": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${register.formData.displayName!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"lastName": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${register.formData.lastName!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"email": (function(){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${register.formData.email!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"username": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${register.formData.username!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"passwordRequired": (function (){
|
"passwordRequired": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if passwordRequired??>
|
<#if passwordRequired??>
|
||||||
return true;
|
return true;
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
})(),
|
})(),
|
||||||
"recaptchaRequired": (function (){
|
"recaptchaRequired": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
<#if passwordRequired??>
|
<#if passwordRequired??>
|
||||||
return true;
|
return true;
|
||||||
</#if>
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
})(),
|
})(),
|
||||||
"recaptchaSiteKey": "${recaptchaSiteKey!''}" || undefined
|
"recaptchaSiteKey": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${recaptchaSiteKey!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"authorizedMailDomains": (function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${authorizedMailDomains!''}" || undefined;
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})(),
|
||||||
|
"authorizedMailDomains": (function(){
|
||||||
|
|
||||||
|
var out = undefined;
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#if authorizedMailDomains??>
|
||||||
|
|
||||||
|
out = [];
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
<#list authorizedMailDomains as authorizedMailDomain>
|
||||||
|
out.push((function (){
|
||||||
|
|
||||||
|
<#attempt>
|
||||||
|
return "${authorizedMailDomain}";
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
})());
|
||||||
|
</#list>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
</#if>
|
||||||
|
<#recover>
|
||||||
|
</#attempt>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
|
||||||
|
})(),
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
@ -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>
|
|
@ -32,7 +32,7 @@ export function generateJavaStackFiles(
|
|||||||
|
|
||||||
return (!homepage ?
|
return (!homepage ?
|
||||||
fallbackGroupId :
|
fallbackGroupId :
|
||||||
url.parse(homepage).host?.split(".").reverse().join(".") ?? fallbackGroupId
|
url.parse(homepage).host?.replace(/:[0-9]+$/,"")?.split(".").reverse().join(".") ?? fallbackGroupId
|
||||||
) + ".keycloak";
|
) + ".keycloak";
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -3,38 +3,56 @@ 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 { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/kcContextMocks/urlResourcesPath";
|
||||||
import { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/kcContextMocks/urlResourcesPath";
|
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;
|
||||||
|
//If urlOrigin is not undefined then it means --externals-assets
|
||||||
|
urlOrigin: undefined | string;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath } = params;
|
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath, urlPathname, urlOrigin } = params;
|
||||||
|
|
||||||
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
||||||
|
|
||||||
let allCssGlobalsToDefine: Record<string, string> = {};
|
let allCssGlobalsToDefine: Record<string, string> = {};
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"destDirPath": pathJoin(themeDirPath, "resources", "build"),
|
"destDirPath":
|
||||||
|
urlOrigin === undefined ?
|
||||||
|
pathJoin(themeDirPath, "resources", "build") :
|
||||||
|
reactAppBuildDirPath,
|
||||||
"srcDirPath": reactAppBuildDirPath,
|
"srcDirPath": reactAppBuildDirPath,
|
||||||
"transformSourceCode": ({ filePath, sourceCode }) => {
|
"transformSourceCode": ({ filePath, sourceCode }) => {
|
||||||
|
|
||||||
if (/\.css?$/i.test(filePath)) {
|
//NOTE: Prevent cycles, excludes the folder we generated for debug in public/
|
||||||
|
if (
|
||||||
|
urlOrigin === undefined &&
|
||||||
|
isInside({
|
||||||
|
"dirPath": pathJoin(reactAppBuildDirPath, subDirOfPublicDirBasename),
|
||||||
|
filePath
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const { cssGlobalsToDefine, fixedCssCode } = replaceImportFromStaticInCssCode(
|
if (urlOrigin === undefined && /\.css?$/i.test(filePath)) {
|
||||||
|
|
||||||
|
const { cssGlobalsToDefine, fixedCssCode } = replaceImportsInCssCode(
|
||||||
{ "cssCode": sourceCode.toString("utf8") }
|
{ "cssCode": sourceCode.toString("utf8") }
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -49,32 +67,37 @@ 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
|
urlOrigin
|
||||||
});
|
});
|
||||||
|
|
||||||
return { "modifiedSourceCode": Buffer.from(fixedJsCode, "utf8") };
|
return { "modifiedSourceCode": Buffer.from(fixedJsCode, "utf8") };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { "modifiedSourceCode": sourceCode };
|
return urlOrigin === undefined ?
|
||||||
|
{ "modifiedSourceCode": sourceCode } :
|
||||||
|
undefined;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
|
const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
|
||||||
"cssGlobalsToDefine": allCssGlobalsToDefine,
|
"cssGlobalsToDefine": allCssGlobalsToDefine,
|
||||||
ftlValuesGlobalName,
|
|
||||||
"indexHtmlCode": fs.readFileSync(
|
"indexHtmlCode": fs.readFileSync(
|
||||||
pathJoin(reactAppBuildDirPath, "index.html")
|
pathJoin(reactAppBuildDirPath, "index.html")
|
||||||
).toString("utf8")
|
).toString("utf8"),
|
||||||
|
urlPathname,
|
||||||
|
urlOrigin
|
||||||
});
|
});
|
||||||
|
|
||||||
pageIds.forEach(pageId => {
|
pageIds.forEach(pageId => {
|
||||||
|
|
||||||
const { ftlCode } = generateFtlFilesCode({ pageId });
|
const { ftlCode } = generateFtlFilesCode({ pageId });
|
||||||
|
|
||||||
|
fs.mkdirSync(themeDirPath, { "recursive": true });
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
pathJoin(themeDirPath, pageId),
|
pathJoin(themeDirPath, pageId),
|
||||||
Buffer.from(ftlCode, "utf8")
|
Buffer.from(ftlCode, "utf8")
|
||||||
@ -91,7 +114,7 @@ export function generateKeycloakThemeResources(
|
|||||||
"destDirPath": tmpDirPath
|
"destDirPath": tmpDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
const themeResourcesDirPath= pathJoin(themeDirPath, "resources");
|
const themeResourcesDirPath = pathJoin(themeDirPath, "resources");
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "login", "resources"),
|
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "login", "resources"),
|
||||||
@ -103,7 +126,7 @@ export function generateKeycloakThemeResources(
|
|||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": themeResourcesDirPath,
|
"srcDirPath": themeResourcesDirPath,
|
||||||
"destDirPath": pathJoin(
|
"destDirPath": pathJoin(
|
||||||
reactAppPublicDirPath,
|
reactAppPublicDirPath,
|
||||||
resourcesPath
|
resourcesPath
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -116,7 +139,7 @@ export function generateKeycloakThemeResources(
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
const keycloakResourcesWithinPublicDirPath =
|
const keycloakResourcesWithinPublicDirPath =
|
||||||
pathJoin(reactAppPublicDirPath, subDirOfPublicDirBasename);
|
pathJoin(reactAppPublicDirPath, subDirOfPublicDirBasename);
|
||||||
|
|
||||||
|
|
||||||
@ -130,10 +153,7 @@ export function generateKeycloakThemeResources(
|
|||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
pathJoin(keycloakResourcesWithinPublicDirPath, ".gitignore"),
|
pathJoin(keycloakResourcesWithinPublicDirPath, ".gitignore"),
|
||||||
Buffer.from([
|
Buffer.from("*", "utf8")
|
||||||
"*",
|
|
||||||
"!.gitignore"
|
|
||||||
].join("\n"))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
child_process.execSync(`rm -r ${tmpDirPath}`);
|
child_process.execSync(`rm -r ${tmpDirPath}`);
|
||||||
|
@ -1,81 +1,3 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources";
|
export * from "./build-keycloak-theme";
|
||||||
import { generateJavaStackFiles } from "./generateJavaStackFiles";
|
|
||||||
import type { ParsedPackageJson } from "./generateJavaStackFiles";
|
|
||||||
import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path";
|
|
||||||
import * as child_process from "child_process";
|
|
||||||
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
|
|
||||||
|
|
||||||
|
|
||||||
const reactProjectDirPath = process.cwd();
|
|
||||||
|
|
||||||
const parsedPackageJson: ParsedPackageJson = require(pathJoin(reactProjectDirPath, "package.json"));
|
|
||||||
|
|
||||||
export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak");
|
|
||||||
|
|
||||||
|
|
||||||
if (require.main === module) {
|
|
||||||
|
|
||||||
console.log("🔏 Building the keycloak theme...⌚");
|
|
||||||
|
|
||||||
generateKeycloakThemeResources({
|
|
||||||
keycloakThemeBuildingDirPath,
|
|
||||||
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
|
||||||
"themeName": parsedPackageJson.name
|
|
||||||
});
|
|
||||||
|
|
||||||
const { jarFilePath } = generateJavaStackFiles({
|
|
||||||
parsedPackageJson,
|
|
||||||
keycloakThemeBuildingDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
child_process.execSync(
|
|
||||||
"mvn package",
|
|
||||||
{ "cwd": keycloakThemeBuildingDirPath }
|
|
||||||
);
|
|
||||||
|
|
||||||
generateDebugFiles({
|
|
||||||
keycloakThemeBuildingDirPath,
|
|
||||||
"packageJsonName": parsedPackageJson.name
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log([
|
|
||||||
'',
|
|
||||||
`✅ Your keycloak theme has been generated and bundled into ./${pathRelative(reactProjectDirPath, jarFilePath)} 🚀`,
|
|
||||||
`It is to be placed in "/opt/jboss/keycloak/standalone/deployments" in the container running a jboss/keycloak Docker image. (Tested with 11.0.3)`,
|
|
||||||
'',
|
|
||||||
'Using Helm (https://github.com/codecentric/helm-charts), edit to reflect:',
|
|
||||||
'',
|
|
||||||
'value.yaml: ',
|
|
||||||
' extraInitContainers: |',
|
|
||||||
' - name: realm-ext-provider',
|
|
||||||
' image: curlimages/curl',
|
|
||||||
' imagePullPolicy: IfNotPresent',
|
|
||||||
' command:',
|
|
||||||
' - sh',
|
|
||||||
' args:',
|
|
||||||
' - -c',
|
|
||||||
` - curl -L -f -S -o /extensions/${pathBasename(jarFilePath)} https://AN.URL.FOR/${pathBasename(jarFilePath)}`,
|
|
||||||
' volumeMounts:',
|
|
||||||
' - name: extensions',
|
|
||||||
' mountPath: /extensions',
|
|
||||||
' ',
|
|
||||||
' extraVolumeMounts: |',
|
|
||||||
' - name: extensions',
|
|
||||||
' mountPath: /opt/jboss/keycloak/standalone/deployments',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'To test your theme locally, with hot reloading, you can spin up a Keycloak container image with the theme loaded by running:',
|
|
||||||
'',
|
|
||||||
`👉 $ ./${pathRelative(reactProjectDirPath, pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename))} 👈`,
|
|
||||||
'',
|
|
||||||
'To enable the theme within keycloak log into the admin console ( 👉 http://localhost:8080 username: admin, password: admin 👈), create a realm (called "myrealm" for example),',
|
|
||||||
`go to your realm settings, click on the theme tab then select ${parsedPackageJson.name}.`,
|
|
||||||
`More details: https://www.keycloak.org/getting-started/getting-started-docker`,
|
|
||||||
'',
|
|
||||||
'Once your container is up and configured 👉 http://localhost:8080/auth/realms/myrealm/account 👈',
|
|
||||||
'',
|
|
||||||
].join("\n"));
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +1,52 @@
|
|||||||
|
|
||||||
import * as crypto from "crypto";
|
import * as crypto from "crypto";
|
||||||
|
import { ftlValuesGlobalName } from "./ftlValuesGlobalName";
|
||||||
|
|
||||||
export function replaceImportFromStaticInJsCode(
|
export function replaceImportsFromStaticInJsCode(
|
||||||
params: {
|
params: {
|
||||||
ftlValuesGlobalName: string;
|
|
||||||
jsCode: string;
|
jsCode: string;
|
||||||
|
urlOrigin: undefined | string;
|
||||||
}
|
}
|
||||||
): { fixedJsCode: string; } {
|
): { fixedJsCode: string; } {
|
||||||
|
|
||||||
const { jsCode, ftlValuesGlobalName } = params;
|
const { jsCode, urlOrigin } = params;
|
||||||
|
|
||||||
const fixedJsCode = jsCode!.replace(
|
const fixedJsCode = jsCode.replace(
|
||||||
/"static\//g,
|
/([a-z]+\.[a-z]+)\+"static\//g,
|
||||||
`window.${ftlValuesGlobalName}.url.resourcesPath.replace(/^\\//,"") + "/build/static/`
|
(...[, group]) =>
|
||||||
|
urlOrigin === undefined ?
|
||||||
|
`window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/` :
|
||||||
|
`("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group} + "static/`
|
||||||
);
|
);
|
||||||
|
|
||||||
return { fixedJsCode };
|
return { fixedJsCode };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceImportFromStaticInCssCode(
|
export function replaceImportsInInlineCssCode(
|
||||||
|
params: {
|
||||||
|
cssCode: string;
|
||||||
|
urlPathname: string;
|
||||||
|
urlOrigin: undefined | string;
|
||||||
|
}
|
||||||
|
): { fixedCssCode: string; } {
|
||||||
|
|
||||||
|
const { cssCode, urlPathname, urlOrigin } = params;
|
||||||
|
|
||||||
|
const fixedCssCode = cssCode.replace(
|
||||||
|
urlPathname === "/" ?
|
||||||
|
/url\(\/([^/][^)]+)\)/g :
|
||||||
|
new RegExp(`url\\(${urlPathname}([^)]+)\\)`, "g"),
|
||||||
|
(...[, group]) => `url(${urlOrigin === undefined ?
|
||||||
|
"${url.resourcesPath}/build/" + group :
|
||||||
|
params.urlOrigin + urlPathname + group})`
|
||||||
|
);
|
||||||
|
|
||||||
|
return { fixedCssCode };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function replaceImportsInCssCode(
|
||||||
params: {
|
params: {
|
||||||
cssCode: string;
|
cssCode: string;
|
||||||
}
|
}
|
||||||
@ -32,7 +59,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 +87,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 +101,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};`),
|
||||||
"}"
|
"}"
|
||||||
|
@ -49,7 +49,7 @@ crawl(".").forEach(filePath => {
|
|||||||
|
|
||||||
child_process.execSync(`rm -r ${tmpDirPath}`);
|
child_process.execSync(`rm -r ${tmpDirPath}`);
|
||||||
|
|
||||||
const targetDirPath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_messages");
|
const targetDirPath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_kcMessages");
|
||||||
|
|
||||||
fs.mkdirSync(targetDirPath, { "recursive": true });
|
fs.mkdirSync(targetDirPath, { "recursive": true });
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ Object.keys(record).forEach(pageType => {
|
|||||||
'//PLEASE DO NOT EDIT MANUALLY',
|
'//PLEASE DO NOT EDIT MANUALLY',
|
||||||
'',
|
'',
|
||||||
'/* spell-checker: disable */',
|
'/* spell-checker: disable */',
|
||||||
`export const messages= ${JSON.stringify(record[pageType], null, 2)} as const;`,
|
`export const kcMessages= ${JSON.stringify(record[pageType], null, 2)};`,
|
||||||
'/* spell-checker: enable */'
|
'/* spell-checker: enable */'
|
||||||
].join("\n"), "utf8")
|
].join("\n"), "utf8")
|
||||||
);
|
);
|
||||||
|
14
src/bin/tools/isInside.ts
Normal file
14
src/bin/tools/isInside.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { relative as pathRelative } from "path";
|
||||||
|
|
||||||
|
export function isInside(
|
||||||
|
params: {
|
||||||
|
dirPath: string;
|
||||||
|
filePath: string;
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
|
||||||
|
const { dirPath, filePath } = params;
|
||||||
|
|
||||||
|
return !pathRelative(dirPath, filePath).startsWith("..");
|
||||||
|
|
||||||
|
}
|
@ -53,13 +53,13 @@ export const Info = memo(({ kcContext, ...props }: { kcContext: KcContext.Info;
|
|||||||
{
|
{
|
||||||
!skipLink &&
|
!skipLink &&
|
||||||
pageRedirectUri !== undefined ?
|
pageRedirectUri !== undefined ?
|
||||||
<p><a href="${pageRedirectUri}">${(msg("backToApplication"))}</a></p>
|
<p><a href={pageRedirectUri}>{(msg("backToApplication"))}</a></p>
|
||||||
:
|
:
|
||||||
actionUri !== undefined ?
|
actionUri !== undefined ?
|
||||||
<p><a href="${actionUri}">${msg("proceedWithAction")}</a></p>
|
<p><a href={actionUri}>{msg("proceedWithAction")}</a></p>
|
||||||
:
|
:
|
||||||
client.baseUrl !== undefined &&
|
client.baseUrl !== undefined &&
|
||||||
<p><a href="${client.baseUrl}">${msg("backToApplication")}</a></p>
|
<p><a href={client.baseUrl}>{msg("backToApplication")}</a></p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -8,8 +8,12 @@ import { Info } from "./Info";
|
|||||||
import { Error } from "./Error";
|
import { Error } from "./Error";
|
||||||
import { LoginResetPassword } from "./LoginResetPassword";
|
import { LoginResetPassword } from "./LoginResetPassword";
|
||||||
import { LoginVerifyEmail } from "./LoginVerifyEmail";
|
import { LoginVerifyEmail } from "./LoginVerifyEmail";
|
||||||
|
import { Terms } from "./Terms";
|
||||||
|
import { LoginOtp } from "./LoginOtp";
|
||||||
|
import { LoginUpdateProfile } from "./LoginUpdateProfile";
|
||||||
|
import { LoginIdpLinkConfirm } from "./LoginIdpLinkConfirm";
|
||||||
|
|
||||||
export const KcApp = memo(({ kcContext, ...props }: { kcContext: KcContext; } & KcProps ) => {
|
export const KcApp = memo(({ kcContext, ...props }: { kcContext: KcContext; } & KcProps) => {
|
||||||
switch (kcContext.pageId) {
|
switch (kcContext.pageId) {
|
||||||
case "login.ftl": return <Login {...{ kcContext, ...props }} />;
|
case "login.ftl": return <Login {...{ kcContext, ...props }} />;
|
||||||
case "register.ftl": return <Register {...{ kcContext, ...props }} />;
|
case "register.ftl": return <Register {...{ kcContext, ...props }} />;
|
||||||
@ -17,5 +21,9 @@ export const KcApp = memo(({ kcContext, ...props }: { kcContext: KcContext; } &
|
|||||||
case "error.ftl": return <Error {...{ kcContext, ...props }} />;
|
case "error.ftl": return <Error {...{ kcContext, ...props }} />;
|
||||||
case "login-reset-password.ftl": return <LoginResetPassword {...{ kcContext, ...props }} />;
|
case "login-reset-password.ftl": return <LoginResetPassword {...{ kcContext, ...props }} />;
|
||||||
case "login-verify-email.ftl": return <LoginVerifyEmail {...{ kcContext, ...props }} />;
|
case "login-verify-email.ftl": return <LoginVerifyEmail {...{ kcContext, ...props }} />;
|
||||||
|
case "terms.ftl": return <Terms {...{ kcContext, ...props }} />;
|
||||||
|
case "login-otp.ftl": return <LoginOtp {...{ kcContext, ...props }} />;
|
||||||
|
case "login-update-profile.ftl": return <LoginUpdateProfile {...{ kcContext, ...props }} />;
|
||||||
|
case "login-idp-link-confirm.ftl": return <LoginIdpLinkConfirm {...{ kcContext, ...props }} />;
|
||||||
}
|
}
|
||||||
});
|
});
|
58
src/lib/components/LoginIdpLinkConfirm.tsx
Normal file
58
src/lib/components/LoginIdpLinkConfirm.tsx
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
import { memo } from "react";
|
||||||
|
import { Template } from "./Template";
|
||||||
|
import type { KcProps } from "./KcProps";
|
||||||
|
import type { KcContext } from "../KcContext";
|
||||||
|
import { useKcMessage } from "../i18n/useKcMessage";
|
||||||
|
import { cx } from "tss-react";
|
||||||
|
|
||||||
|
export const LoginIdpLinkConfirm = memo(({ kcContext, ...props }: { kcContext: KcContext.LoginIdpLinkConfirm; } & KcProps) => {
|
||||||
|
|
||||||
|
const { msg } = useKcMessage();
|
||||||
|
|
||||||
|
const { url, idpAlias } = kcContext;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Template
|
||||||
|
{...{ kcContext, ...props }}
|
||||||
|
headerNode={msg("confirmLinkIdpTitle")}
|
||||||
|
formNode={
|
||||||
|
<form id="kc-register-form" action={url.loginAction} method="post">
|
||||||
|
<div className={cx(props.kcFormGroupClass)}>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={cx(
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonDefaultClass,
|
||||||
|
props.kcButtonBlockClass,
|
||||||
|
props.kcButtonLargeClass
|
||||||
|
)}
|
||||||
|
name="submitAction"
|
||||||
|
id="updateProfile"
|
||||||
|
value="updateProfile"
|
||||||
|
>
|
||||||
|
{msg("confirmLinkIdpReviewProfile")}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={cx(
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonDefaultClass,
|
||||||
|
props.kcButtonBlockClass,
|
||||||
|
props.kcButtonLargeClass
|
||||||
|
)}
|
||||||
|
name="submitAction"
|
||||||
|
id="linkAccount"
|
||||||
|
value="linkAccount"
|
||||||
|
>
|
||||||
|
{msg("confirmLinkIdpContinue", idpAlias)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
145
src/lib/components/LoginOtp.tsx
Normal file
145
src/lib/components/LoginOtp.tsx
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import { useEffect, memo } from "react";
|
||||||
|
import { Template } from "./Template";
|
||||||
|
import type { KcProps } from "./KcProps";
|
||||||
|
import type { KcContext } from "../KcContext";
|
||||||
|
import { useKcMessage } from "../i18n/useKcMessage";
|
||||||
|
import { appendHead } from "../tools/appendHead";
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
import { cx } from "tss-react";
|
||||||
|
|
||||||
|
export const LoginOtp = memo(({ kcContext, ...props }: { kcContext: KcContext.LoginOtp; } & KcProps) => {
|
||||||
|
|
||||||
|
const { otpLogin, url } = kcContext;
|
||||||
|
|
||||||
|
const { msg, msgStr } = useKcMessage();
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => {
|
||||||
|
|
||||||
|
let isCleanedUp = false;
|
||||||
|
|
||||||
|
appendHead({
|
||||||
|
"type": "javascript",
|
||||||
|
"src": pathJoin(
|
||||||
|
kcContext.url.resourcesCommonPath,
|
||||||
|
"node_modules/jquery/dist/jquery.min.js"
|
||||||
|
)
|
||||||
|
}).then(() => {
|
||||||
|
|
||||||
|
if (isCleanedUp) return;
|
||||||
|
|
||||||
|
evaluateInlineScript();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => { isCleanedUp = true };
|
||||||
|
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Template
|
||||||
|
{...{ kcContext, ...props }}
|
||||||
|
headerNode={msg("doLogIn")}
|
||||||
|
formNode={
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="kc-otp-login-form"
|
||||||
|
className={cx(props.kcFormClass)}
|
||||||
|
action={url.loginAction}
|
||||||
|
method="post"
|
||||||
|
>
|
||||||
|
{
|
||||||
|
otpLogin.userOtpCredentials.length > 1 &&
|
||||||
|
<div className={cx(props.kcFormGroupClass)}>
|
||||||
|
<div className={cx(props.kcInputWrapperClass)}>
|
||||||
|
{
|
||||||
|
otpLogin.userOtpCredentials.map(otpCredential =>
|
||||||
|
<div key={otpCredential.id} className={cx(props.kcSelectOTPListClass)}>
|
||||||
|
<input type="hidden" value="${otpCredential.id}" />
|
||||||
|
<div className={cx(props.kcSelectOTPListItemClass)}>
|
||||||
|
<span className={cx(props.kcAuthenticatorOtpCircleClass)} />
|
||||||
|
<h2 className={cx(props.kcSelectOTPItemHeadingClass)}>
|
||||||
|
{otpCredential.userLabel}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div className={cx(props.kcFormGroupClass)}>
|
||||||
|
<div className={cx(props.kcLabelWrapperClass)}>
|
||||||
|
<label htmlFor="otp" className={cx(props.kcLabelClass)}>
|
||||||
|
{msg("loginOtpOneTime")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={cx(props.kcInputWrapperClass)}>
|
||||||
|
<input
|
||||||
|
id="otp"
|
||||||
|
name="otp"
|
||||||
|
autoComplete="off"
|
||||||
|
type="text"
|
||||||
|
className={cx(props.kcInputClass)}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={cx(props.kcFormGroupClass)}>
|
||||||
|
<div id="kc-form-options" className={cx(props.kcFormOptionsClass)}>
|
||||||
|
<div className={cx(props.kcFormOptionsWrapperClass)} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="kc-form-buttons" className={cx(props.kcFormButtonsClass)}>
|
||||||
|
<input
|
||||||
|
className={cx(
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonPrimaryClass,
|
||||||
|
props.kcButtonBlockClass,
|
||||||
|
props.kcButtonLargeClass
|
||||||
|
)}
|
||||||
|
name="login"
|
||||||
|
id="kc-login"
|
||||||
|
type="submit"
|
||||||
|
value={msgStr("doLogIn")}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form >
|
||||||
|
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
declare const $: any;
|
||||||
|
|
||||||
|
function evaluateInlineScript() {
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
// Card Single Select
|
||||||
|
$('.card-pf-view-single-select').click(function (this: any) {
|
||||||
|
if ($(this).hasClass('active')) { $(this).removeClass('active'); $(this).children().removeAttr('name'); }
|
||||||
|
else {
|
||||||
|
$('.card-pf-view-single-select').removeClass('active');
|
||||||
|
$('.card-pf-view-single-select').children().removeAttr('name');
|
||||||
|
$(this).addClass('active'); $(this).children().attr('name', 'selectedCredentialId');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var defaultCred = $('.card-pf-view-single-select')[0];
|
||||||
|
if (defaultCred) {
|
||||||
|
defaultCred.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
@ -66,7 +66,7 @@ export const LoginResetPassword = memo(({ kcContext, ...props }: { kcContext: Kc
|
|||||||
props.kcButtonBlockClass, props.kcButtonLargeClass
|
props.kcButtonBlockClass, props.kcButtonLargeClass
|
||||||
)}
|
)}
|
||||||
type="submit"
|
type="submit"
|
||||||
defaultValue={msgStr("doSubmit")}
|
value={msgStr("doSubmit")}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
130
src/lib/components/LoginUpdateProfile.tsx
Normal file
130
src/lib/components/LoginUpdateProfile.tsx
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
import { memo } from "react";
|
||||||
|
import { Template } from "./Template";
|
||||||
|
import type { KcProps } from "./KcProps";
|
||||||
|
import type { KcContext } from "../KcContext";
|
||||||
|
import { useKcMessage } from "../i18n/useKcMessage";
|
||||||
|
import { cx } from "tss-react";
|
||||||
|
|
||||||
|
export const LoginUpdateProfile = memo(({ kcContext, ...props }: { kcContext: KcContext.LoginUpdateProfile; } & KcProps) => {
|
||||||
|
|
||||||
|
const { msg, msgStr } = useKcMessage();
|
||||||
|
|
||||||
|
const { url, user, messagesPerField, isAppInitiatedAction } = kcContext;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Template
|
||||||
|
{...{ kcContext, ...props }}
|
||||||
|
headerNode={msg("loginProfileTitle")}
|
||||||
|
formNode={
|
||||||
|
<form id="kc-update-profile-form" className={cx(props.kcFormClass)} action={url.loginAction} method="post">
|
||||||
|
{user.editUsernameAllowed &&
|
||||||
|
<div className={cx(props.kcFormGroupClass, messagesPerField.printIfExists("username", props.kcFormGroupErrorClass))}>
|
||||||
|
<div className={cx(props.kcLabelWrapperClass)}>
|
||||||
|
<label htmlFor="username" className={cx(props.kcLabelClass)}>
|
||||||
|
{msg("username")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className={cx(props.kcInputWrapperClass)}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="username"
|
||||||
|
name="username"
|
||||||
|
defaultValue={user.username ?? ""}
|
||||||
|
className={cx(props.kcInputClass)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className={cx(props.kcFormGroupClass, messagesPerField.printIfExists("email", props.kcFormGroupErrorClass))}>
|
||||||
|
<div className={cx(props.kcLabelWrapperClass)}>
|
||||||
|
<label htmlFor="email" className={cx(props.kcLabelClass)}>
|
||||||
|
{msg("email")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className={cx(props.kcInputWrapperClass)}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
defaultValue={user.email ?? ""}
|
||||||
|
className={cx(props.kcInputClass)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={cx(props.kcFormGroupClass, messagesPerField.printIfExists("firstName", props.kcFormGroupErrorClass))}>
|
||||||
|
<div className={cx(props.kcLabelWrapperClass)}>
|
||||||
|
<label htmlFor="firstName" className={cx(props.kcLabelClass)}>
|
||||||
|
{msg("firstName")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className={cx(props.kcInputWrapperClass)}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="firstName"
|
||||||
|
name="firstName"
|
||||||
|
defaultValue={user.firstName ?? ""}
|
||||||
|
className={cx(props.kcInputClass)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={cx(props.kcFormGroupClass, messagesPerField.printIfExists("lastName", props.kcFormGroupErrorClass))}>
|
||||||
|
<div className={cx(props.kcLabelWrapperClass)}>
|
||||||
|
<label htmlFor="lastName" className={cx(props.kcLabelClass)}>
|
||||||
|
{msg("lastName")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className={cx(props.kcInputWrapperClass)}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="lastName"
|
||||||
|
name="lastName"
|
||||||
|
defaultValue={user.lastName ?? ""}
|
||||||
|
className={cx(props.kcInputClass)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={cx(props.kcFormGroupClass)}>
|
||||||
|
<div id="kc-form-options" className={cx(props.kcFormOptionsClass)}>
|
||||||
|
<div className={cx(props.kcFormOptionsWrapperClass)} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="kc-form-buttons" className={cx(props.kcFormButtonsClass)}>
|
||||||
|
{
|
||||||
|
isAppInitiatedAction ?
|
||||||
|
<>
|
||||||
|
<input
|
||||||
|
className={cx(props.kcButtonClass, props.kcButtonPrimaryClass, props.kcButtonLargeClass)}
|
||||||
|
type="submit"
|
||||||
|
defaultValue={msgStr("doSubmit")}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className={cx(props.kcButtonClass, props.kcButtonDefaultClass, props.kcButtonLargeClass)}
|
||||||
|
type="submit"
|
||||||
|
name="cancel-aia"
|
||||||
|
value="true"
|
||||||
|
>
|
||||||
|
{msg("doCancel")}
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
<input
|
||||||
|
className={cx(props.kcButtonClass, props.kcButtonPrimaryClass, props.kcButtonBlockClass, props.kcButtonLargeClass)}
|
||||||
|
type="submit"
|
||||||
|
defaultValue={msgStr("doSubmit")}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ export const Register = memo(({ kcContext, ...props }: { kcContext: KcContext.Re
|
|||||||
|
|
||||||
<div id="kc-form-buttons" className={cx(props.kcFormButtonsClass)}>
|
<div id="kc-form-buttons" className={cx(props.kcFormButtonsClass)}>
|
||||||
<input className={cx(props.kcButtonClass, props.kcButtonPrimaryClass, props.kcButtonBlockClass, props.kcButtonLargeClass)} type="submit"
|
<input className={cx(props.kcButtonClass, props.kcButtonPrimaryClass, props.kcButtonBlockClass, props.kcButtonLargeClass)} type="submit"
|
||||||
defaultValue={msgStr("doRegister")} />
|
value={msgStr("doRegister")} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form >
|
</form >
|
||||||
|
@ -25,8 +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) => {
|
||||||
|
|
||||||
@ -60,34 +59,35 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
realm, locale, auth,
|
realm, locale, auth,
|
||||||
url, message, isAppInitiatedAction
|
url, message, isAppInitiatedAction
|
||||||
}= kcContext;
|
} = kcContext;
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(() => {
|
||||||
|
|
||||||
if( !realm.internationalizationEnabled ){
|
if (!realm.internationalizationEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( locale !== undefined );
|
assert(locale !== undefined);
|
||||||
|
|
||||||
if( kcLanguageTag === getBestMatchAmongKcLanguageTag(locale.current) ){
|
if (kcLanguageTag === getBestMatchAmongKcLanguageTag(locale.current)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location.href =
|
window.location.href =
|
||||||
locale.supported.find(({ languageTag }) => languageTag === kcLanguageTag)!.url;
|
locale.supported.find(({ languageTag }) => languageTag === kcLanguageTag)!.url;
|
||||||
|
|
||||||
},[kcLanguageTag]);
|
}, [kcLanguageTag]);
|
||||||
|
|
||||||
const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false);
|
const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
let isUnmounted = false;
|
let isUnmounted = false;
|
||||||
|
const cleanups: (() => void)[] = [];
|
||||||
|
|
||||||
const toArr = (x: string | readonly string[] | undefined) =>
|
const toArr = (x: string | readonly string[] | undefined) =>
|
||||||
typeof x === "string" ? x.split(" ") : x ?? [];
|
typeof x === "string" ? x.split(" ") : x ?? [];
|
||||||
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
@ -114,13 +114,29 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
document.getElementsByTagName("html")[0]
|
if (props.kcHtmlClass !== undefined) {
|
||||||
.classList
|
|
||||||
.add(cx(props.kcHtmlClass));
|
|
||||||
|
|
||||||
return () => { isUnmounted = true; };
|
const htmlClassList =
|
||||||
|
document.getElementsByTagName("html")[0]
|
||||||
|
.classList;
|
||||||
|
|
||||||
}, []);
|
const tokens = cx(props.kcHtmlClass).split(" ")
|
||||||
|
|
||||||
|
htmlClassList.add(...tokens);
|
||||||
|
|
||||||
|
cleanups.push(() => htmlClassList.remove(...tokens));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
|
||||||
|
isUnmounted = true;
|
||||||
|
|
||||||
|
cleanups.forEach(f => f());
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}, [props.kcHtmlClass]);
|
||||||
|
|
||||||
if (!isExtraCssLoaded) {
|
if (!isExtraCssLoaded) {
|
||||||
return null;
|
return null;
|
||||||
@ -152,7 +168,7 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
locale.supported.map(
|
locale.supported.map(
|
||||||
({ languageTag }) =>
|
({ languageTag }) =>
|
||||||
<li key={languageTag} className="kc-dropdown-item">
|
<li key={languageTag} className="kc-dropdown-item">
|
||||||
<a href="#" onClick={onChangeLanguageClickFactory(languageTag)}>
|
<a href="#" onClick={onChangeLanguageClickFactory(languageTag)}>
|
||||||
{getKcLanguageTagLabel(languageTag)}
|
{getKcLanguageTagLabel(languageTag)}
|
||||||
@ -218,21 +234,21 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{showUsernameNode}
|
{showUsernameNode}
|
||||||
<div className={cx(props.kcFormGroupClass)}>
|
<div className={cx(props.kcFormGroupClass)}>
|
||||||
<div id="kc-username">
|
<div id="kc-username">
|
||||||
<label id="kc-attempted-username">{auth?.attemptedUsername}</label>
|
<label id="kc-attempted-username">{auth?.attemptedUsername}</label>
|
||||||
<a id="reset-login" href={url.loginRestartFlowUrl}>
|
<a id="reset-login" href={url.loginRestartFlowUrl}>
|
||||||
<div className="kc-login-tooltip">
|
<div className="kc-login-tooltip">
|
||||||
<i className={cx(props.kcResetFlowIcon)}></i>
|
<i className={cx(props.kcResetFlowIcon)}></i>
|
||||||
<span className="kc-tooltip-text">{msg("restartLoginTooltip")}</span>
|
<span className="kc-tooltip-text">{msg("restartLoginTooltip")}</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
)
|
</>
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</header>
|
</header>
|
||||||
|
57
src/lib/components/Terms.tsx
Normal file
57
src/lib/components/Terms.tsx
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import { memo } from "react";
|
||||||
|
import { Template } from "./Template";
|
||||||
|
import type { KcProps } from "./KcProps";
|
||||||
|
import type { KcContext } from "../KcContext";
|
||||||
|
import { useKcMessage } from "../i18n/useKcMessage";
|
||||||
|
import { cx } from "tss-react";
|
||||||
|
|
||||||
|
export const Terms = memo(({ kcContext, ...props }: { kcContext: KcContext.Terms; } & KcProps) => {
|
||||||
|
|
||||||
|
const { msg, msgStr } = useKcMessage();
|
||||||
|
|
||||||
|
const { url } = kcContext;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Template
|
||||||
|
{...{ kcContext, ...props }}
|
||||||
|
displayMessage={false}
|
||||||
|
headerNode={msg("termsTitle")}
|
||||||
|
formNode={
|
||||||
|
<>
|
||||||
|
<div id="kc-terms-text">
|
||||||
|
{msg("termsText")}
|
||||||
|
</div>
|
||||||
|
<form className="form-actions" action={url.loginAction} method="POST">
|
||||||
|
<input
|
||||||
|
className={cx(
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonPrimaryClass,
|
||||||
|
props.kcButtonLargeClass
|
||||||
|
)}
|
||||||
|
name="accept"
|
||||||
|
id="kc-accept"
|
||||||
|
type="submit"
|
||||||
|
value={msgStr("doAccept")}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
className={cx(
|
||||||
|
props.kcButtonClass,
|
||||||
|
props.kcButtonDefaultClass,
|
||||||
|
props.kcButtonLargeClass
|
||||||
|
)}
|
||||||
|
name="cancel"
|
||||||
|
id="kc-decline"
|
||||||
|
type="submit"
|
||||||
|
value={msgStr("doDecline")}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
<div className="clearfix" />
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
||||||
import { messages } from "./generated_messages/login";
|
import { kcMessages } from "./kcMessages/login";
|
||||||
|
|
||||||
export type KcLanguageTag = keyof typeof messages;
|
export type KcLanguageTag = keyof typeof kcMessages;
|
||||||
|
|
||||||
export type LanguageLabel =
|
export type LanguageLabel =
|
||||||
/* spell-checker: disable */
|
/* spell-checker: disable */
|
||||||
@ -40,7 +40,7 @@ export function getKcLanguageTagLabel(language: KcLanguageTag): LanguageLabel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const availableLanguages = objectKeys(messages);
|
const availableLanguages = objectKeys(kcMessages);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass in "fr-FR" or "français" for example, it will return the AvailableLanguage
|
* Pass in "fr-FR" or "français" for example, it will return the AvailableLanguage
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//PLEASE DO NOT EDIT MANUALLY
|
//PLEASE DO NOT EDIT MANUALLY
|
||||||
|
|
||||||
/* spell-checker: disable */
|
/* spell-checker: disable */
|
||||||
export const messages= {
|
export const kcMessages= {
|
||||||
"ca": {
|
"ca": {
|
||||||
"doSave": "Desa",
|
"doSave": "Desa",
|
||||||
"doCancel": "Cancel·la",
|
"doCancel": "Cancel·la",
|
||||||
@ -3060,5 +3060,5 @@ export const messages= {
|
|||||||
"locale_ru": "Русский",
|
"locale_ru": "Русский",
|
||||||
"locale_zh-CN": "中文简体"
|
"locale_zh-CN": "中文简体"
|
||||||
}
|
}
|
||||||
} as const;
|
};
|
||||||
/* spell-checker: enable */
|
/* spell-checker: enable */
|
@ -2,7 +2,7 @@
|
|||||||
//PLEASE DO NOT EDIT MANUALLY
|
//PLEASE DO NOT EDIT MANUALLY
|
||||||
|
|
||||||
/* spell-checker: disable */
|
/* spell-checker: disable */
|
||||||
export const messages= {
|
export const kcMessages= {
|
||||||
"ca": {
|
"ca": {
|
||||||
"invalidPasswordHistoryMessage": "Contrasenya incorrecta: no pot ser igual a cap de les últimes {0} contrasenyes.",
|
"invalidPasswordHistoryMessage": "Contrasenya incorrecta: no pot ser igual a cap de les últimes {0} contrasenyes.",
|
||||||
"invalidPasswordMinDigitsMessage": "Contraseña incorrecta: debe contener al menos {0} caracteres numéricos.",
|
"invalidPasswordMinDigitsMessage": "Contraseña incorrecta: debe contener al menos {0} caracteres numéricos.",
|
||||||
@ -240,5 +240,5 @@ export const messages= {
|
|||||||
"pairwiseFailedToGetRedirectURIs": "无法从服务器获得重定向URL",
|
"pairwiseFailedToGetRedirectURIs": "无法从服务器获得重定向URL",
|
||||||
"pairwiseRedirectURIsMismatch": "客户端的重定向URI与服务器端获取的URI配置不匹配。"
|
"pairwiseRedirectURIsMismatch": "客户端的重定向URI与服务器端获取的URI配置不匹配。"
|
||||||
}
|
}
|
||||||
} as const;
|
};
|
||||||
/* spell-checker: enable */
|
/* spell-checker: enable */
|
@ -2,7 +2,7 @@
|
|||||||
//PLEASE DO NOT EDIT MANUALLY
|
//PLEASE DO NOT EDIT MANUALLY
|
||||||
|
|
||||||
/* spell-checker: disable */
|
/* spell-checker: disable */
|
||||||
export const messages= {
|
export const kcMessages= {
|
||||||
"ca": {
|
"ca": {
|
||||||
"emailVerificationSubject": "Verificació d'email",
|
"emailVerificationSubject": "Verificació d'email",
|
||||||
"emailVerificationBody": "Algú ha creat un compte de {2} amb aquesta adreça de correu electrònic. Si has estat tu, fes clic a l'enllaç següent per verificar la teva adreça de correu electrònic.\n\n{0}\n\nAquest enllaç expirarà en {1} minuts.\n\nSi tu no has creat aquest compte, simplement ignora aquest missatge.",
|
"emailVerificationBody": "Algú ha creat un compte de {2} amb aquesta adreça de correu electrònic. Si has estat tu, fes clic a l'enllaç següent per verificar la teva adreça de correu electrònic.\n\n{0}\n\nAquest enllaç expirarà en {1} minuts.\n\nSi tu no has creat aquest compte, simplement ignora aquest missatge.",
|
||||||
@ -634,5 +634,5 @@ export const messages= {
|
|||||||
"eventUpdateTotpBody": "您账户的OTP 配置在{0} 由 {1}更改. 如非本人操作,请联系管理员。",
|
"eventUpdateTotpBody": "您账户的OTP 配置在{0} 由 {1}更改. 如非本人操作,请联系管理员。",
|
||||||
"eventUpdateTotpBodyHtml": "<p>您账户的OTP 配置在{0} 由 {1}更改. 如非本人操作,请联系管理员。</p>"
|
"eventUpdateTotpBodyHtml": "<p>您账户的OTP 配置在{0} 由 {1}更改. 如非本人操作,请联系管理员。</p>"
|
||||||
}
|
}
|
||||||
} as const;
|
};
|
||||||
/* spell-checker: enable */
|
/* spell-checker: enable */
|
@ -2,7 +2,7 @@
|
|||||||
//PLEASE DO NOT EDIT MANUALLY
|
//PLEASE DO NOT EDIT MANUALLY
|
||||||
|
|
||||||
/* spell-checker: disable */
|
/* spell-checker: disable */
|
||||||
export const messages= {
|
export const kcMessages= {
|
||||||
"ca": {
|
"ca": {
|
||||||
"doLogIn": "Inicia sessió",
|
"doLogIn": "Inicia sessió",
|
||||||
"doRegister": "Registra't",
|
"doRegister": "Registra't",
|
||||||
@ -4360,5 +4360,5 @@ export const messages= {
|
|||||||
"invalidParameterMessage": "无效的参数 : {0}",
|
"invalidParameterMessage": "无效的参数 : {0}",
|
||||||
"alreadyLoggedIn": "您已经登录"
|
"alreadyLoggedIn": "您已经登录"
|
||||||
}
|
}
|
||||||
} as const;
|
};
|
||||||
/* spell-checker: enable */
|
/* spell-checker: enable */
|
33
src/lib/i18n/kcMessages/login.ts
Normal file
33
src/lib/i18n/kcMessages/login.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
import { kcMessages } from "../generated_kcMessages/login";
|
||||||
|
import { Evt } from "evt";
|
||||||
|
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
||||||
|
|
||||||
|
export const evtTermsUpdated = Evt.asNonPostable(Evt.create<void>());
|
||||||
|
|
||||||
|
(["termsText", "doAccept", "doDecline", "termsTitle"] as const).forEach(key =>
|
||||||
|
objectKeys(kcMessages).forEach(kcLanguage =>
|
||||||
|
Object.defineProperty(
|
||||||
|
kcMessages[kcLanguage],
|
||||||
|
key,
|
||||||
|
(() => {
|
||||||
|
|
||||||
|
let value = key === "termsText" ? "⏳" : kcMessages[kcLanguage][key];
|
||||||
|
|
||||||
|
return {
|
||||||
|
"enumerable": true,
|
||||||
|
"get": () => value,
|
||||||
|
"set": (newValue: string) => {
|
||||||
|
value = newValue;
|
||||||
|
Evt.asPostable(evtTermsUpdated).post();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
})()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export { kcMessages };
|
||||||
|
|
@ -10,7 +10,7 @@ const wrap = createUseGlobalState(
|
|||||||
kcContext?.locale?.current ??
|
kcContext?.locale?.current ??
|
||||||
navigator.language
|
navigator.language
|
||||||
),
|
),
|
||||||
{ "persistance": "cookie" }
|
{ "persistance": "localStorage" }
|
||||||
);
|
);
|
||||||
|
|
||||||
export const { useKcLanguageTag } = wrap;
|
export const { useKcLanguageTag } = wrap;
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
|
|
||||||
|
import { useCallback, useReducer } from "react";
|
||||||
import { useKcLanguageTag } from "./useKcLanguageTag";
|
import { useKcLanguageTag } from "./useKcLanguageTag";
|
||||||
import { messages } from "./generated_messages/login";
|
import { kcMessages, evtTermsUpdated } from "./kcMessages/login";
|
||||||
import { useConstCallback } from "powerhooks";
|
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { id } from "evt/tools/typeSafety/id";
|
import { useEvt } from "evt/hooks";
|
||||||
|
//NOTE for later: https://github.com/remarkjs/react-markdown/blob/236182ecf30bd89c1e5a7652acaf8d0bf81e6170/src/renderers.js#L7-L35
|
||||||
|
import ReactMarkdown from "react-markdown";
|
||||||
|
|
||||||
export type MessageKey = keyof typeof messages["en"];
|
export type MessageKey = keyof typeof kcMessages["en"];
|
||||||
|
|
||||||
export function useKcMessage() {
|
export function useKcMessage() {
|
||||||
|
|
||||||
const { kcLanguageTag } = useKcLanguageTag();
|
const { kcLanguageTag } = useKcLanguageTag();
|
||||||
|
|
||||||
const msgStr = useConstCallback(
|
const [trigger, forceUpdate] = useReducer((counter: number) => counter + 1, 0);
|
||||||
|
|
||||||
|
useEvt(ctx => evtTermsUpdated.attach(ctx, forceUpdate), []);
|
||||||
|
|
||||||
|
const msgStr = useCallback(
|
||||||
(key: MessageKey, ...args: (string | undefined)[]): string => {
|
(key: MessageKey, ...args: (string | undefined)[]): string => {
|
||||||
|
|
||||||
let str: string = messages[kcLanguageTag as any as "en"][key] ?? messages["en"][key];
|
let str: string = kcMessages[kcLanguageTag as any as "en"][key] ?? kcMessages["en"][key];
|
||||||
|
|
||||||
args.forEach((arg, i) => {
|
args.forEach((arg, i) => {
|
||||||
|
|
||||||
@ -28,14 +34,16 @@ export function useKcMessage() {
|
|||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
}
|
},
|
||||||
|
[kcLanguageTag, trigger]
|
||||||
);
|
);
|
||||||
|
|
||||||
const msg = useConstCallback(
|
const msg = useCallback<(...args: Parameters<typeof msgStr>) => ReactNode>(
|
||||||
id<(...args: Parameters<typeof msgStr>) => ReactNode>(
|
(key, ...args) =>
|
||||||
(key, ...args) =>
|
<ReactMarkdown allowDangerousHtml renderers={key === "termsText" ? undefined : { "paragraph": "span" }}>
|
||||||
<span className={key} dangerouslySetInnerHTML={{ "__html": msgStr(key, ...args) }} />
|
{msgStr(key, ...args)}
|
||||||
)
|
</ReactMarkdown>,
|
||||||
|
[msgStr]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { msg, msgStr };
|
return { msg, msgStr };
|
||||||
|
@ -3,6 +3,7 @@ export * from "./KcContext";
|
|||||||
export * from "./i18n/KcLanguageTag";
|
export * from "./i18n/KcLanguageTag";
|
||||||
export * from "./i18n/useKcLanguageTag";
|
export * from "./i18n/useKcLanguageTag";
|
||||||
export * from "./i18n/useKcMessage";
|
export * from "./i18n/useKcMessage";
|
||||||
|
export * from "./i18n/kcMessages/login";
|
||||||
|
|
||||||
export * from "./components/KcProps";
|
export * from "./components/KcProps";
|
||||||
export * from "./components/Login";
|
export * from "./components/Login";
|
||||||
@ -12,7 +13,9 @@ export * from "./components/Info";
|
|||||||
export * from "./components/Error";
|
export * from "./components/Error";
|
||||||
export * from "./components/LoginResetPassword";
|
export * from "./components/LoginResetPassword";
|
||||||
export * from "./components/LoginVerifyEmail";
|
export * from "./components/LoginVerifyEmail";
|
||||||
|
export * from "./keycloakJsAdapter";
|
||||||
|
|
||||||
export * from "./tools/assert";
|
export * from "./tools/assert";
|
||||||
|
|
||||||
|
|
||||||
export * as kcContextMocks from "./kcContextMocks";
|
export * as kcContextMocks from "./kcContextMocks";
|
@ -10,12 +10,19 @@ 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 |
|
||||||
|
KcContext.Terms | KcContext.LoginOtp | KcContext.LoginUpdateProfile |
|
||||||
|
KcContext.LoginIdpLinkConfirm;
|
||||||
|
|
||||||
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 +34,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 +62,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 +95,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;
|
||||||
@ -118,9 +125,14 @@ export declare namespace KcContext {
|
|||||||
passwordRequired: boolean;
|
passwordRequired: boolean;
|
||||||
recaptchaRequired: boolean;
|
recaptchaRequired: boolean;
|
||||||
recaptchaSiteKey?: string;
|
recaptchaSiteKey?: string;
|
||||||
|
/**
|
||||||
|
* Defined when you use the keycloak-mail-whitelisting keycloak plugin
|
||||||
|
* (https://github.com/micedre/keycloak-mail-whitelisting)
|
||||||
|
*/
|
||||||
|
authorizedMailDomains?: 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,24 +144,58 @@ 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";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Terms = Common & {
|
||||||
|
pageId: "terms.ftl";
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LoginOtp = Common & {
|
||||||
|
pageId: "login-otp.ftl";
|
||||||
|
otpLogin: {
|
||||||
|
userOtpCredentials: { id: string; userLabel: string; }[];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LoginUpdateProfile = Common & {
|
||||||
|
pageId: "login-update-profile.ftl";
|
||||||
|
user: {
|
||||||
|
editUsernameAllowed: boolean;
|
||||||
|
username?: string;
|
||||||
|
email?: string;
|
||||||
|
firstName?: string;
|
||||||
|
lastName?: string;
|
||||||
|
};
|
||||||
|
messagesPerField: {
|
||||||
|
printIfExists<T>(
|
||||||
|
key: "username" | "email" | "firstName" | "lastName",
|
||||||
|
x: T
|
||||||
|
): T | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LoginIdpLinkConfirm = Common & {
|
||||||
|
pageId: "login-idp-link-confirm.ftl";
|
||||||
|
idpAlias: string;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
doExtends<KcContext["pageId"], PageId>();
|
doExtends<KcContext["pageId"], PageId>();
|
||||||
|
@ -1,201 +1 @@
|
|||||||
|
export * from "./kcContextMocks";
|
||||||
|
|
||||||
import type { KcContext } from "../KcContext";
|
|
||||||
import { getEvtKcLanguage } from "../i18n/useKcLanguageTag";
|
|
||||||
import { getKcLanguageTagLabel } from "../i18n/KcLanguageTag";
|
|
||||||
//NOTE: Aside because we want to be able to import them from node
|
|
||||||
import { resourcesCommonPath, resourcesPath } from "./urlResourcesPath";
|
|
||||||
|
|
||||||
export const kcTemplateContext: KcContext.Template = {
|
|
||||||
"url": {
|
|
||||||
"loginAction": "#",
|
|
||||||
"resourcesPath": "/" + resourcesPath,
|
|
||||||
"resourcesCommonPath": "/" + resourcesCommonPath,
|
|
||||||
"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",
|
|
||||||
},
|
|
||||||
"realm": {
|
|
||||||
"displayName": "myrealm",
|
|
||||||
"displayNameHtml": "myrealm",
|
|
||||||
"internationalizationEnabled": true,
|
|
||||||
"registrationEmailAsUsername": true,
|
|
||||||
},
|
|
||||||
"locale": {
|
|
||||||
"supported": [
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=de",
|
|
||||||
"languageTag": "de"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=no",
|
|
||||||
"languageTag": "no"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=ru",
|
|
||||||
"languageTag": "ru"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=sv",
|
|
||||||
"languageTag": "sv"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=pt-BR",
|
|
||||||
"languageTag": "pt-BR"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=lt",
|
|
||||||
"languageTag": "lt"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=en",
|
|
||||||
"languageTag": "en"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=it",
|
|
||||||
"languageTag": "it"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=fr",
|
|
||||||
"languageTag": "fr"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=zh-CN",
|
|
||||||
"languageTag": "zh-CN"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=es",
|
|
||||||
"languageTag": "es"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=cs",
|
|
||||||
"languageTag": "cs"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=ja",
|
|
||||||
"languageTag": "ja"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=sk",
|
|
||||||
"languageTag": "sk"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=pl",
|
|
||||||
"languageTag": "pl"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=ca",
|
|
||||||
"languageTag": "ca"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=nl",
|
|
||||||
"languageTag": "nl"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=tr",
|
|
||||||
"languageTag": "tr"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"current": null as any
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"showUsername": false,
|
|
||||||
"showResetCredentials": false,
|
|
||||||
"showTryAnotherWayLink": false
|
|
||||||
},
|
|
||||||
"scripts": [],
|
|
||||||
"message": {
|
|
||||||
"type": "success",
|
|
||||||
"summary": "This is a test message"
|
|
||||||
},
|
|
||||||
"isAppInitiatedAction": false,
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.defineProperty(
|
|
||||||
kcTemplateContext.locale!,
|
|
||||||
"current",
|
|
||||||
{
|
|
||||||
"get": () => getKcLanguageTagLabel(getEvtKcLanguage().state),
|
|
||||||
"enumerable": true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const kcLoginContext: KcContext.Login = {
|
|
||||||
...kcTemplateContext,
|
|
||||||
"pageId": "login.ftl",
|
|
||||||
"url": {
|
|
||||||
...kcTemplateContext.url,
|
|
||||||
"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"
|
|
||||||
},
|
|
||||||
"realm": {
|
|
||||||
...kcTemplateContext.realm,
|
|
||||||
"loginWithEmailAllowed": true,
|
|
||||||
"rememberMe": true,
|
|
||||||
"password": true,
|
|
||||||
"resetPasswordAllowed": true,
|
|
||||||
"registrationAllowed": true
|
|
||||||
},
|
|
||||||
"auth": kcTemplateContext.auth!,
|
|
||||||
"social": {
|
|
||||||
"displayInfo": true
|
|
||||||
},
|
|
||||||
"usernameEditDisabled": false,
|
|
||||||
"login": {
|
|
||||||
"rememberMe": false
|
|
||||||
},
|
|
||||||
"registrationDisabled": false,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const kcRegisterContext: KcContext.Register = {
|
|
||||||
...kcTemplateContext,
|
|
||||||
"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"
|
|
||||||
},
|
|
||||||
"messagesPerField": {
|
|
||||||
"printIfExists": (...[,x]) => x
|
|
||||||
},
|
|
||||||
"scripts": [],
|
|
||||||
"isAppInitiatedAction": false,
|
|
||||||
"pageId": "register.ftl",
|
|
||||||
"register": {
|
|
||||||
"formData": {}
|
|
||||||
},
|
|
||||||
"passwordRequired": true,
|
|
||||||
"recaptchaRequired": false
|
|
||||||
};
|
|
||||||
|
|
||||||
export const kcInfoContext: KcContext.Info ={
|
|
||||||
...kcTemplateContext,
|
|
||||||
"pageId": "info.ftl",
|
|
||||||
"messageHeader": "<Message header>",
|
|
||||||
"requiredActions": undefined,
|
|
||||||
"skipLink": false,
|
|
||||||
"actionUri": "#",
|
|
||||||
"client": {
|
|
||||||
"baseUrl": "#"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const kcErrorContext: KcContext.Error = {
|
|
||||||
...kcTemplateContext,
|
|
||||||
"pageId": "error.ftl",
|
|
||||||
"client": {
|
|
||||||
"baseUrl": "#"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const kcLoginResetPasswordContext: KcContext.LoginResetPassword = {
|
|
||||||
...kcTemplateContext,
|
|
||||||
"pageId": "login-reset-password.ftl",
|
|
||||||
"realm":{
|
|
||||||
...kcTemplateContext.realm,
|
|
||||||
"loginWithEmailAllowed": false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const kcLoginVerifyEmailContext: KcContext.LoginVerifyEmail = {
|
|
||||||
...kcTemplateContext,
|
|
||||||
"pageId": "login-verify-email.ftl"
|
|
||||||
};
|
|
||||||
|
|
249
src/lib/kcContextMocks/kcContextMocks.ts
Normal file
249
src/lib/kcContextMocks/kcContextMocks.ts
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
|
||||||
|
import type { KcContext } from "../KcContext";
|
||||||
|
import { getEvtKcLanguage } from "../i18n/useKcLanguageTag";
|
||||||
|
import { getKcLanguageTagLabel } from "../i18n/KcLanguageTag";
|
||||||
|
//NOTE: Aside because we want to be able to import them from node
|
||||||
|
import { resourcesCommonPath, resourcesPath } from "./urlResourcesPath";
|
||||||
|
|
||||||
|
const kcCommonContext: KcContext.Common = {
|
||||||
|
"url": {
|
||||||
|
"loginAction": "#",
|
||||||
|
"resourcesPath": `${process.env["PUBLIC_URL"]}/${resourcesPath}`,
|
||||||
|
"resourcesCommonPath": `${process.env["PUBLIC_URL"]}/${resourcesCommonPath}`,
|
||||||
|
"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",
|
||||||
|
},
|
||||||
|
"realm": {
|
||||||
|
"displayName": "myrealm",
|
||||||
|
"displayNameHtml": "myrealm",
|
||||||
|
"internationalizationEnabled": true,
|
||||||
|
"registrationEmailAsUsername": true,
|
||||||
|
},
|
||||||
|
"locale": {
|
||||||
|
"supported": [
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=de",
|
||||||
|
"languageTag": "de"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=no",
|
||||||
|
"languageTag": "no"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=ru",
|
||||||
|
"languageTag": "ru"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=sv",
|
||||||
|
"languageTag": "sv"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=pt-BR",
|
||||||
|
"languageTag": "pt-BR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=lt",
|
||||||
|
"languageTag": "lt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=en",
|
||||||
|
"languageTag": "en"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=it",
|
||||||
|
"languageTag": "it"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=fr",
|
||||||
|
"languageTag": "fr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=zh-CN",
|
||||||
|
"languageTag": "zh-CN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=es",
|
||||||
|
"languageTag": "es"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=cs",
|
||||||
|
"languageTag": "cs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=ja",
|
||||||
|
"languageTag": "ja"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=sk",
|
||||||
|
"languageTag": "sk"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=pl",
|
||||||
|
"languageTag": "pl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=ca",
|
||||||
|
"languageTag": "ca"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=nl",
|
||||||
|
"languageTag": "nl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "/auth/realms/myrealm/login-actions/authenticate?client_id=account&tab_id=HoAx28ja4xg&execution=ee6c2834-46a4-4a20-a1b6-f6d6f6451b36&kc_locale=tr",
|
||||||
|
"languageTag": "tr"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"current": null as any
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"showUsername": false,
|
||||||
|
"showResetCredentials": false,
|
||||||
|
"showTryAnotherWayLink": false
|
||||||
|
},
|
||||||
|
"scripts": [],
|
||||||
|
"message": {
|
||||||
|
"type": "success",
|
||||||
|
"summary": "This is a test message"
|
||||||
|
},
|
||||||
|
"isAppInitiatedAction": false,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(
|
||||||
|
kcCommonContext.locale!,
|
||||||
|
"current",
|
||||||
|
{
|
||||||
|
"get": () => getKcLanguageTagLabel(getEvtKcLanguage().state),
|
||||||
|
"enumerable": true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const kcLoginContext: KcContext.Login = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "login.ftl",
|
||||||
|
"url": {
|
||||||
|
...kcCommonContext.url,
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"realm": {
|
||||||
|
...kcCommonContext.realm,
|
||||||
|
"loginWithEmailAllowed": true,
|
||||||
|
"rememberMe": true,
|
||||||
|
"password": true,
|
||||||
|
"resetPasswordAllowed": true,
|
||||||
|
"registrationAllowed": true
|
||||||
|
},
|
||||||
|
"auth": kcCommonContext.auth!,
|
||||||
|
"social": {
|
||||||
|
"displayInfo": true
|
||||||
|
},
|
||||||
|
"usernameEditDisabled": false,
|
||||||
|
"login": {
|
||||||
|
"rememberMe": false
|
||||||
|
},
|
||||||
|
"registrationDisabled": false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcRegisterContext: KcContext.Register = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"messagesPerField": {
|
||||||
|
"printIfExists": (...[, x]) => x
|
||||||
|
},
|
||||||
|
"scripts": [],
|
||||||
|
"isAppInitiatedAction": false,
|
||||||
|
"pageId": "register.ftl",
|
||||||
|
"register": {
|
||||||
|
"formData": {}
|
||||||
|
},
|
||||||
|
"passwordRequired": true,
|
||||||
|
"recaptchaRequired": false,
|
||||||
|
"authorizedMailDomains": [
|
||||||
|
"example.com",
|
||||||
|
"another-example.com",
|
||||||
|
"*.yet-another-example.com",
|
||||||
|
"*.example.com",
|
||||||
|
"hello-world.com"
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcInfoContext: KcContext.Info = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "info.ftl",
|
||||||
|
"messageHeader": "<Message header>",
|
||||||
|
"requiredActions": undefined,
|
||||||
|
"skipLink": false,
|
||||||
|
"actionUri": "#",
|
||||||
|
"client": {
|
||||||
|
"baseUrl": "#"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcErrorContext: KcContext.Error = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "error.ftl",
|
||||||
|
"client": {
|
||||||
|
"baseUrl": "#"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcLoginResetPasswordContext: KcContext.LoginResetPassword = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "login-reset-password.ftl",
|
||||||
|
"realm": {
|
||||||
|
...kcCommonContext.realm,
|
||||||
|
"loginWithEmailAllowed": false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcLoginVerifyEmailContext: KcContext.LoginVerifyEmail = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "login-verify-email.ftl"
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcTermsContext: KcContext.Terms = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "terms.ftl"
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcLoginOtpContext: KcContext.LoginOtp = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "login-otp.ftl",
|
||||||
|
"otpLogin": {
|
||||||
|
"userOtpCredentials": [
|
||||||
|
{
|
||||||
|
"id": "id1",
|
||||||
|
"userLabel": "label1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "id2",
|
||||||
|
"userLabel": "label2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcLoginUpdateProfileContext: KcContext.LoginUpdateProfile = {
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "login-update-profile.ftl",
|
||||||
|
"user": {
|
||||||
|
"editUsernameAllowed": true,
|
||||||
|
"username": "anUsername",
|
||||||
|
"email": "foo@example.com",
|
||||||
|
"firstName": "aFirstName",
|
||||||
|
"lastName": "aLastName"
|
||||||
|
},
|
||||||
|
"messagesPerField": {
|
||||||
|
"printIfExists": () => undefined
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const kcLoginIdpLinkConfirmContext: KcContext.LoginIdpLinkConfirm ={
|
||||||
|
...kcCommonContext,
|
||||||
|
"pageId": "login-idp-link-confirm.ftl",
|
||||||
|
"idpAlias": "FranceConnect"
|
||||||
|
};
|
118
src/lib/keycloakJsAdapter.ts
Normal file
118
src/lib/keycloakJsAdapter.ts
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export declare namespace keycloak_js {
|
||||||
|
|
||||||
|
export type KeycloakPromiseCallback<T> = (result: T) => void;
|
||||||
|
export class KeycloakPromise<TSuccess, TError> extends Promise<TSuccess> {
|
||||||
|
success(callback: KeycloakPromiseCallback<TSuccess>): KeycloakPromise<TSuccess, TError>;
|
||||||
|
error(callback: KeycloakPromiseCallback<TError>): KeycloakPromise<TSuccess, TError>;
|
||||||
|
}
|
||||||
|
export interface KeycloakAdapter {
|
||||||
|
login(options?: KeycloakLoginOptions): KeycloakPromise<void, void>;
|
||||||
|
logout(options?: KeycloakLogoutOptions): KeycloakPromise<void, void>;
|
||||||
|
register(options?: KeycloakLoginOptions): KeycloakPromise<void, void>;
|
||||||
|
accountManagement(): KeycloakPromise<void, void>;
|
||||||
|
redirectUri(options: { redirectUri: string; }, encodeHash: boolean): string;
|
||||||
|
}
|
||||||
|
export interface KeycloakLogoutOptions {
|
||||||
|
redirectUri?: string;
|
||||||
|
}
|
||||||
|
export interface KeycloakLoginOptions {
|
||||||
|
scope?: string;
|
||||||
|
redirectUri?: string;
|
||||||
|
prompt?: 'none' | 'login';
|
||||||
|
action?: string;
|
||||||
|
maxAge?: number;
|
||||||
|
loginHint?: string;
|
||||||
|
idpHint?: string;
|
||||||
|
locale?: string;
|
||||||
|
cordovaOptions?: { [optionName: string]: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export type KeycloakInstance = Record<
|
||||||
|
"createLoginUrl" |
|
||||||
|
"createLogoutUrl" |
|
||||||
|
"createRegisterUrl",
|
||||||
|
(options: KeycloakLoginOptions | undefined) => string
|
||||||
|
> & {
|
||||||
|
createAccountUrl(): string;
|
||||||
|
redirectUri?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOTE: This is just a slightly modified version of the default adapter in keycloak-js
|
||||||
|
* The goal here is just to be able to inject search param in url before keycloak redirect.
|
||||||
|
* Our use case for it is to pass over the login screen the states of useGlobalState
|
||||||
|
* namely isDarkModeEnabled, lgn...
|
||||||
|
*/
|
||||||
|
export function createKeycloakAdapter(
|
||||||
|
params: {
|
||||||
|
keycloakInstance: keycloak_js.KeycloakInstance;
|
||||||
|
transformUrlBeforeRedirect(url: string): string;
|
||||||
|
}
|
||||||
|
): keycloak_js.KeycloakAdapter {
|
||||||
|
|
||||||
|
const { keycloakInstance, transformUrlBeforeRedirect } = params;
|
||||||
|
|
||||||
|
const neverResolvingPromise: keycloak_js.KeycloakPromise<void, void> = Object.defineProperties(
|
||||||
|
new Promise(() => { }),
|
||||||
|
{
|
||||||
|
"success": { "value": () => { } },
|
||||||
|
"error": { "value": () => { } }
|
||||||
|
}
|
||||||
|
) as any;
|
||||||
|
|
||||||
|
return {
|
||||||
|
"login": options => {
|
||||||
|
window.location.href=
|
||||||
|
transformUrlBeforeRedirect(
|
||||||
|
keycloakInstance.createLoginUrl(
|
||||||
|
options
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return neverResolvingPromise;
|
||||||
|
},
|
||||||
|
"logout": options => {
|
||||||
|
window.location.replace(
|
||||||
|
transformUrlBeforeRedirect(
|
||||||
|
keycloakInstance.createLogoutUrl(
|
||||||
|
options
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return neverResolvingPromise;
|
||||||
|
},
|
||||||
|
"register": options => {
|
||||||
|
window.location.href =
|
||||||
|
transformUrlBeforeRedirect(
|
||||||
|
keycloakInstance.createRegisterUrl(
|
||||||
|
options
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return neverResolvingPromise;
|
||||||
|
},
|
||||||
|
"accountManagement": () => {
|
||||||
|
var accountUrl = transformUrlBeforeRedirect(keycloakInstance.createAccountUrl());
|
||||||
|
if (typeof accountUrl !== 'undefined') {
|
||||||
|
window.location.href = accountUrl;
|
||||||
|
} else {
|
||||||
|
throw new Error("Not supported by the OIDC server");
|
||||||
|
}
|
||||||
|
return neverResolvingPromise;
|
||||||
|
},
|
||||||
|
"redirectUri": options => {
|
||||||
|
if (options && options.redirectUri) {
|
||||||
|
return options.redirectUri;
|
||||||
|
} else if (keycloakInstance.redirectUri) {
|
||||||
|
return keycloakInstance.redirectUri;
|
||||||
|
} else {
|
||||||
|
return window.location.href;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { generateKeycloakThemeResources } from "../bin/build-keycloak-theme/generateKeycloakThemeResources";
|
import { generateKeycloakThemeResources } from "../bin/build-keycloak-theme/generateKeycloakThemeResources";
|
||||||
import {
|
import {
|
||||||
setupSampleReactProject,
|
setupSampleReactProject,
|
||||||
sampleReactProjectDirPath
|
sampleReactProjectDirPath
|
||||||
} from "./setupSampleReactProject";
|
} from "./setupSampleReactProject";
|
||||||
@ -9,8 +9,10 @@ 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/",
|
||||||
|
"urlOrigin": undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ setupSampleReactProject();
|
|||||||
const binDirPath= pathJoin(getProjectRoot(), "dist", "bin");
|
const binDirPath= pathJoin(getProjectRoot(), "dist", "bin");
|
||||||
|
|
||||||
st.execSyncTrace(
|
st.execSyncTrace(
|
||||||
|
//`node ${pathJoin(binDirPath, "build-keycloak-theme")} --external-assets`,
|
||||||
`node ${pathJoin(binDirPath, "build-keycloak-theme")}`,
|
`node ${pathJoin(binDirPath, "build-keycloak-theme")}`,
|
||||||
{ "cwd": sampleReactProjectDirPath }
|
{ "cwd": sampleReactProjectDirPath }
|
||||||
);
|
);
|
||||||
@ -21,4 +22,3 @@ st.execSyncTrace(
|
|||||||
`node ${pathJoin(binDirPath, "install-builtin-keycloak-themes")}`,
|
`node ${pathJoin(binDirPath, "install-builtin-keycloak-themes")}`,
|
||||||
{ "cwd": sampleReactProjectDirPath }
|
{ "cwd": sampleReactProjectDirPath }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,30 +1,47 @@
|
|||||||
|
|
||||||
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",
|
|
||||||
"jsCode": `
|
"jsCode": `
|
||||||
function f() {
|
function f() {
|
||||||
return a.p + "static/js/" + ({}[e] || e) + "." + {
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
||||||
3: "0664cdc0"
|
3: "0664cdc0"
|
||||||
}[e] + ".chunk.js"
|
}[e] + ".chunk.js"
|
||||||
}
|
}
|
||||||
|
|
||||||
function f2() {
|
function f2() {
|
||||||
return a.p +"static/js/" + ({}[e] || e) + "." + {
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
||||||
3: "0664cdc0"
|
3: "0664cdc0"
|
||||||
}[e] + ".chunk.js"
|
}[e] + ".chunk.js"
|
||||||
}
|
}
|
||||||
`
|
`,
|
||||||
|
"urlOrigin": undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log({ fixedJsCode });
|
const { fixedJsCode: fixedJsCodeExternal } = replaceImportsFromStaticInJsCode({
|
||||||
|
"jsCode": `
|
||||||
|
function f() {
|
||||||
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
||||||
|
3: "0664cdc0"
|
||||||
|
}[e] + ".chunk.js"
|
||||||
|
}
|
||||||
|
|
||||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportFromStaticInCssCode({
|
function f2() {
|
||||||
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
||||||
|
3: "0664cdc0"
|
||||||
|
}[e] + ".chunk.js"
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
"urlOrigin": "https://www.example.com"
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log({ fixedJsCode, fixedJsCodeExternal });
|
||||||
|
|
||||||
|
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
||||||
"cssCode": `
|
"cssCode": `
|
||||||
|
|
||||||
.my-div {
|
.my-div {
|
||||||
@ -45,6 +62,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