keycloak-scim/import.mjs
2022-03-06 16:25:37 +01:00

27 lines
682 B
JavaScript
Executable file

#!/usr/bin/env node
import { readFile } from "node:fs/promises";
import KcAdminClient from "@keycloak/keycloak-admin-client";
const consoleClientConfig = JSON.parse(
await readFile(new URL("./security-admin-console-v2.json", import.meta.url))
);
const adminClient = new KcAdminClient.default({
baseUrl: "http://localhost:8180",
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);
}