2021-02-20 11:51:44 +01:00
|
|
|
<p align="center">
|
2021-02-27 14:57:49 +01:00
|
|
|
<img src="https://user-images.githubusercontent.com/6702424/109387840-eba11f80-7903-11eb-9050-db1dad883f78.png">
|
2021-02-20 11:51:44 +01:00
|
|
|
</p>
|
|
|
|
<p align="center">
|
2021-02-27 14:28:50 +01:00
|
|
|
<i>🔏 Keycloak theme generator for Reacts app 🔏</i>
|
2021-02-20 11:51:44 +01:00
|
|
|
<br>
|
|
|
|
<br>
|
2021-03-05 20:43:22 +01:00
|
|
|
<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/npm/dw/keycloakify">
|
|
|
|
<img src="https://img.shields.io/npm/l/keycloakify">
|
2021-02-20 10:53:26 +00:00
|
|
|
</p>
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-27 22:49:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
**!!! This module is under active developement. It is not usable yet!!!**
|
|
|
|
|
2021-02-27 18:19:02 +01:00
|
|
|
# Motivations
|
2021-02-23 13:11:56 +01:00
|
|
|
|
|
|
|
The problem:
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
When we redirected to Keycloak the user suffers from a harsh context switch.
|
2021-02-23 18:08:46 +01:00
|
|
|
On je login/register pages the language is set back to default and the theme is different that the one on the app.
|
2021-02-23 13:11:56 +01:00
|
|
|
|
2021-02-23 13:14:43 +01:00
|
|
|
Keycloak does offer a way to customize theses pages but it requires a lot of raw HTML/CSS hacking
|
|
|
|
to reproduce the look and feel of a specific app. Not mentioning the maintenance cost of such an endeavour.
|
2021-02-23 13:11:56 +01:00
|
|
|
|
|
|
|
Wouldn't it be great if we could just design the login and register pages as if they where part of our app while
|
|
|
|
still letting Keycloak handle the heavy lifting of actually authenticating the users?
|
|
|
|
|
2021-03-05 20:43:22 +01:00
|
|
|
Here is `yarn add keycloakify` for you 🍸
|
2021-02-23 13:11:56 +01:00
|
|
|
|
2021-02-23 18:11:03 +01:00
|
|
|
TODO: Insert video after.
|
2021-02-23 13:11:56 +01:00
|
|
|
|
|
|
|
# How to use
|
|
|
|
|
|
|
|
## Setting up the build tool
|
|
|
|
|
2021-03-05 20:43:22 +01:00
|
|
|
Add `keycloakify` to the dev dependencies of your project `npm install --save-dev keycloakify` or `yarn add --dev keycloakify`
|
2021-02-23 13:11:56 +01:00
|
|
|
then configure your `package.json` build's script to build the keycloak's theme by adding `&& build-keycloak-theme`.
|
|
|
|
|
|
|
|
Typically you will get:
|
|
|
|
|
|
|
|
`package.json`:
|
|
|
|
```json
|
|
|
|
"devDependencies": {
|
2021-03-05 20:43:22 +01:00
|
|
|
"keycloakify": "^0.0.10"
|
2021-02-23 13:11:56 +01:00
|
|
|
},
|
|
|
|
"scripts": {
|
2021-02-27 02:15:17 +01:00
|
|
|
"build": "react-scripts build && build-keycloak-theme"
|
2021-02-23 13:11:56 +01:00
|
|
|
},
|
|
|
|
```
|
|
|
|
|
|
|
|
Then build your app with `yarn run build` or `npm run build`, you will be provided with instructions
|
|
|
|
about how to load the theme into Keycloak.
|
|
|
|
|
2021-02-23 18:11:03 +01:00
|
|
|
[](https://youtu.be/xTz0Rj7i2v8)
|
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
## Developing your login and register pages in your React app
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
# How to implement context persistance
|
|
|
|
|
|
|
|
If you want dark mode preference, language and others users preferences your can do so
|
|
|
|
very easily by using [`powerhooks/useGlobalState`](https://github.com/garronej/powerhooks)
|
|
|
|
|
|
|
|
WARNING: `powerhooks` is still a work in progress.
|
|
|
|
|
|
|
|
# REQUIREMENTS
|
|
|
|
|
|
|
|
This tools assumes you are bundling your app with Webpack (tested with 4.44.2) .
|
|
|
|
It assumes there is a `build/` directory at the root of your react project directory containing a `index.html` file
|
|
|
|
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
|
2021-02-27 18:19:02 +01:00
|
|
|
- For development, (testing the theme in a local container ): `rm`, `mkdir`, `wget`, `unzip` are assumed to be available
|
|
|
|
and `docker` up and running.
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
NOTE: This build tool has only be tested on MacOS.
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
# API Reference
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
## The build tool
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
Part of the lib that runs with node, at build time.
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
- `npx build-keycloak-theme`: Builds the theme, the CWD is assumed to be the root of your react project.
|
|
|
|
- `npx download-sample-keycloak-themes`: Downloads the keycloak default themes (for development purposes)
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-27 18:19:02 +01:00
|
|
|
## The fronted lib ( imported into your react app )
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
Part of the lib that you import in your react project and runs on the browser.
|
2021-02-21 23:06:42 +01:00
|
|
|
|
2021-02-23 13:11:56 +01:00
|
|
|
**TODO**
|