Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
fdb9ae6c40 | |||
3c82ffc0ab | |||
5dd3103aba | |||
84fc81f531 | |||
a20cbc62a5 | |||
e6a93e2838 | |||
3cff54561f | |||
e50a6a7876 | |||
b887ec839b |
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,3 +1,16 @@
|
||||
### **2.0.4** (2021-07-03)
|
||||
|
||||
- Fix: #7
|
||||
|
||||
### **2.0.3** (2021-06-30)
|
||||
|
||||
- Escape double quote in ftl to js conversion #15
|
||||
- Update readme
|
||||
|
||||
### **2.0.2** (2021-06-28)
|
||||
|
||||
- Updagte README for implementing non incuded pages
|
||||
|
||||
### **2.0.1** (2021-06-28)
|
||||
|
||||
- Update documentation for v2
|
||||
|
14
README.md
14
README.md
@ -208,7 +208,9 @@ and the result you can expect:
|
||||
If you want to go beyond only customizing the CSS you can re-implement some of the
|
||||
pages or event add new ones.
|
||||
|
||||
If you want to go this way checkout the demo setup provided [here](https://github.com/garronej/keycloakify-demo-app/tree/look_and_feel)
|
||||
If you want to go this way checkout the demo setup provided [here](https://github.com/garronej/keycloakify-demo-app/tree/look_and_feel).
|
||||
If you prefer a real life example you can checkout [onyxia-web's source](https://github.com/InseeFrLab/onyxia-web/tree/main/src/app/components/KcApp).
|
||||
The web app is in production [here](https://datalab.sspcloud.fr).
|
||||
|
||||
Main takeaways are:
|
||||
- You must declare your custom pages in the package.json. [example](https://github.com/garronej/keycloakify-demo-app/blob/4eb2a9f63e9823e653b2d439495bda55e5ecc134/package.json#L17-L22)
|
||||
@ -286,16 +288,10 @@ Then to load your own therms of services using [like this](https://github.com/ga
|
||||
|
||||
# Some pages still have the default theme. Why?
|
||||
|
||||
**NEW in v1.2 it is now much more easy to add support for custom pages since the
|
||||
Keycloak context is now automatically converted into a JavaScript object (kcContext).
|
||||
In v2 (coming soon) it won't be required to fork for adding support for custom pages.**
|
||||
|
||||
This project only support the most common user facing pages of Keycloak login.
|
||||
This project only support out of the box 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.
|
||||
If you need to customize pages that are not supported yet or if you need to implement some non standard `.ftl` pages please refer to [Advanced pages configuration](#advanced-pages-configuration).
|
||||
|
||||
# GitHub Actions
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.4",
|
||||
"description": "Keycloak theme generator for Reacts app",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -113,7 +113,7 @@
|
||||
|
||||
|
||||
<#attempt>
|
||||
"${object?no_esc}"
|
||||
"${object?replace('"', '\\"')?no_esc}"
|
||||
<#recover>
|
||||
/* couldn't convert into string non hash, non method, non boolean, non enumerable object */
|
||||
undefined;
|
||||
|
@ -8,9 +8,9 @@ import { deepAssign } from "../tools/deepAssign";
|
||||
|
||||
|
||||
export type ExtendsKcContextBase<
|
||||
KcContextExtended extends ({ pageId: string; } | undefined)
|
||||
KcContextExtended extends { pageId: string; }
|
||||
> =
|
||||
KcContextExtended extends undefined ?
|
||||
[KcContextExtended] extends [never] ?
|
||||
KcContextBase :
|
||||
AndByDiscriminatingKey<
|
||||
"pageId",
|
||||
@ -18,7 +18,7 @@ export type ExtendsKcContextBase<
|
||||
KcContextBase
|
||||
>;
|
||||
|
||||
export function getKcContext<KcContextExtended extends ({ pageId: string; } | undefined) = undefined>(
|
||||
export function getKcContext<KcContextExtended extends { pageId: string; } = never>(
|
||||
params?: {
|
||||
mockPageId?: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
||||
mockData?: readonly DeepPartial<ExtendsKcContextBase<KcContextExtended>>[];
|
||||
@ -51,22 +51,15 @@ export function getKcContext<KcContextExtended extends ({ pageId: string; } | un
|
||||
|
||||
}
|
||||
|
||||
const kcContext: any = { "pageId": mockPageId };
|
||||
const kcContext: any = {};
|
||||
|
||||
deepAssign({
|
||||
"target": kcContext,
|
||||
"source": kcContextCommonMock
|
||||
"source": kcContextDefaultMock !== undefined ?
|
||||
kcContextDefaultMock :
|
||||
{ "pageId": mockPageId, ...kcContextCommonMock, }
|
||||
});
|
||||
|
||||
if (kcContextDefaultMock !== undefined) {
|
||||
|
||||
deepAssign({
|
||||
"target": kcContext,
|
||||
"source": kcContextDefaultMock
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (partialKcContextCustomMock !== undefined) {
|
||||
|
||||
deepAssign({
|
||||
|
@ -2,6 +2,7 @@
|
||||
import { assert } from "tsafe/assert";
|
||||
import { is } from "tsafe/is";
|
||||
|
||||
//Warning: Be mindful that because of array this is not idempotent.
|
||||
export function deepAssign(
|
||||
params: {
|
||||
target: Record<string, unknown>;
|
||||
|
@ -6,202 +6,245 @@ import { same } from "evt/tools/inDepth";
|
||||
import { doExtends } from "tsafe/doExtends";
|
||||
import { assert } from "tsafe/assert";
|
||||
import { kcContextMocks, kcContextCommonMock } from "../../lib/getKcContext/kcContextMocks";
|
||||
import { deepClone } from "../../lib/tools/deepClone";
|
||||
import { deepClone } from "../../lib/tools/deepClone";
|
||||
import type { Any } from "ts-toolbelt";
|
||||
|
||||
{
|
||||
|
||||
const authorizedMailDomains = [
|
||||
"example.com",
|
||||
"another-example.com",
|
||||
"*.yet-another-example.com",
|
||||
"*.example.com",
|
||||
"hello-world.com"
|
||||
];
|
||||
const authorizedMailDomains = [
|
||||
"example.com",
|
||||
"another-example.com",
|
||||
"*.yet-another-example.com",
|
||||
"*.example.com",
|
||||
"hello-world.com"
|
||||
];
|
||||
|
||||
const displayName = "this is an overwritten common value";
|
||||
const displayName = "this is an overwritten common value";
|
||||
|
||||
const aNonStandardValue = "a non standard value";
|
||||
const aNonStandardValue1 = "a non standard value 1";
|
||||
const aNonStandardValue2 = "a non standard value 2";
|
||||
|
||||
type KcContextExtended = {
|
||||
pageId: "register.ftl";
|
||||
authorizedMailDomains: string[];
|
||||
} | {
|
||||
pageId: "my-extra-page-1.ftl";
|
||||
} | {
|
||||
pageId: "my-extra-page-2.ftl";
|
||||
aNonStandardValue: string;
|
||||
};
|
||||
type KcContextExtended = {
|
||||
pageId: "register.ftl";
|
||||
authorizedMailDomains: string[];
|
||||
} | {
|
||||
pageId: "info.ftl";
|
||||
aNonStandardValue1: string;
|
||||
} | {
|
||||
pageId: "my-extra-page-1.ftl";
|
||||
} | {
|
||||
pageId: "my-extra-page-2.ftl";
|
||||
aNonStandardValue2: string;
|
||||
};
|
||||
|
||||
const getKcContextProxy = (
|
||||
params: {
|
||||
mockPageId: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
||||
}
|
||||
) => {
|
||||
|
||||
const { mockPageId } = params;
|
||||
|
||||
const { kcContext } = getKcContext<KcContextExtended>({
|
||||
mockPageId,
|
||||
"mockData": [
|
||||
{
|
||||
"pageId": "login.ftl",
|
||||
"realm": { displayName }
|
||||
},
|
||||
{
|
||||
"pageId": "info.ftl",
|
||||
aNonStandardValue1
|
||||
},
|
||||
{
|
||||
"pageId": "register.ftl",
|
||||
authorizedMailDomains
|
||||
},
|
||||
{
|
||||
"pageId": "my-extra-page-2.ftl",
|
||||
aNonStandardValue2
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
return { kcContext };
|
||||
|
||||
};
|
||||
|
||||
{
|
||||
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Login>, 1>();
|
||||
|
||||
assert(same(
|
||||
//NOTE: deepClone for printIfExists or other functions...
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
mock.realm.displayName = displayName;
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
function getKcContextProxy(
|
||||
params: {
|
||||
mockPageId: ExtendsKcContextBase<KcContextExtended>["pageId"];
|
||||
}
|
||||
) {
|
||||
|
||||
const { mockPageId } = params;
|
||||
{
|
||||
const pageId = "info.ftl";
|
||||
|
||||
const { kcContext } = getKcContext<KcContextExtended>({
|
||||
mockPageId,
|
||||
"mockData": [
|
||||
{
|
||||
"pageId": "login.ftl",
|
||||
"realm": { displayName }
|
||||
},
|
||||
{
|
||||
"pageId": "register.ftl",
|
||||
authorizedMailDomains
|
||||
},
|
||||
{
|
||||
"pageId": "my-extra-page-2.ftl",
|
||||
aNonStandardValue
|
||||
}
|
||||
]
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Info & { pageId: typeof pageId; aNonStandardValue1: string; }>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
Object.assign(mock, { aNonStandardValue1 });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
const pageId = "register.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Register & { pageId: typeof pageId; authorizedMailDomains: string[]; }>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
Object.assign(mock, { authorizedMailDomains });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-2.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Common & { pageId: typeof pageId; aNonStandardValue2: string; }>, 1>();
|
||||
|
||||
kcContext.aNonStandardValue2;
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId, aNonStandardValue2 });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-1.ftl";
|
||||
|
||||
console.log("We expect a warning here =>");
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase.Common & { pageId: typeof pageId; }>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContext({
|
||||
"mockPageId": pageId
|
||||
});
|
||||
|
||||
return { kcContext };
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId= "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Login>();
|
||||
|
||||
assert(same(
|
||||
//NOTE: deepClone for printIfExists or other functions...
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
mock.realm.displayName = displayName;
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
const pageId = "register.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Register>();
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase | undefined>, 1>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
|
||||
Object.assign(mock, { authorizedMailDomains });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-2.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<typeof kcContext, KcContextBase>();
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Common>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId, aNonStandardValue });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
console.log("PASS no extension");
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const pageId = "my-extra-page-1.ftl";
|
||||
|
||||
console.log("We expect a warning here =>");
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<typeof kcContext, KcContextBase>();
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase.Common>();
|
||||
|
||||
assert(same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
|
||||
const mock = deepClone(kcContextCommonMock);
|
||||
|
||||
Object.assign(mock, { pageId });
|
||||
|
||||
return mock;
|
||||
|
||||
})()
|
||||
));
|
||||
|
||||
console.log(`PASS ${pageId}`);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
const { kcContext } = getKcContext();
|
||||
|
||||
//@ts-expect-error
|
||||
doExtends<Any.Equals<typeof kcContext, any>, 1>();
|
||||
doExtends<Any.Equals<typeof kcContext, KcContextBase | undefined>, 1>();
|
||||
|
||||
doExtends<typeof kcContext, KcContextBase | undefined>();
|
||||
assert(kcContext === undefined);
|
||||
|
||||
console.log("PASS no extension, no mock");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user