2021-07-15 20:56:25 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
import { readFile } from "node:fs/promises";
|
2021-08-26 08:39:35 +00:00
|
|
|
import KcAdminClient from "@keycloak/keycloak-admin-client";
|
2021-07-15 20:56:25 +00:00
|
|
|
|
|
|
|
const consoleClientConfig = JSON.parse(
|
|
|
|
await readFile(new URL("./security-admin-console-v2.json", import.meta.url))
|
|
|
|
);
|
|
|
|
|
|
|
|
const adminClient = new KcAdminClient.default({
|
2022-03-06 15:25:37 +00:00
|
|
|
baseUrl: "http://localhost:8180",
|
2021-07-15 20:56:25 +00:00
|
|
|
realmName: "master",
|
|
|
|
});
|
|
|
|
|
|
|
|
await adminClient.auth({
|
|
|
|
username: "admin",
|
|
|
|
password: "admin",
|
|
|
|
grantType: "password",
|
|
|
|
clientId: "admin-cli",
|
|
|
|
});
|
|
|
|
|
|
|
|
const adminConsoleClient = await adminClient.clients.find({
|
|
|
|
clientId: "security-admin-console-v2",
|
|
|
|
});
|
|
|
|
|
|
|
|
if (adminConsoleClient.length === 0) {
|
|
|
|
adminClient.clients.create(consoleClientConfig);
|
|
|
|
}
|