keycloak-scim/import.mjs

28 lines
670 B
JavaScript
Raw Normal View History

2021-07-15 20:56:25 +00:00
#!/usr/bin/env node
import { readFile } from "node:fs/promises";
import KcAdminClient from "keycloak-admin";
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/auth",
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);
}