2023-07-07 14:34:54 +00:00
|
|
|
import KeycloakAdminClient from "@keycloak/keycloak-admin-client";
|
|
|
|
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
|
|
|
|
|
|
|
const adminClient = new KeycloakAdminClient({
|
2023-08-14 14:41:58 +00:00
|
|
|
baseUrl: process.env.KEYCLOAK_SERVER || "http://127.0.0.1:8180",
|
2023-07-07 14:34:54 +00:00
|
|
|
realmName: "master",
|
|
|
|
});
|
|
|
|
|
|
|
|
await adminClient.auth({
|
|
|
|
username: "admin",
|
|
|
|
password: "admin",
|
|
|
|
grantType: "password",
|
|
|
|
clientId: "admin-cli",
|
|
|
|
});
|
|
|
|
|
2023-08-14 14:41:58 +00:00
|
|
|
export async function useTheme() {
|
|
|
|
const masterRealm = await adminClient.realms.findOne({ realm: "master" });
|
|
|
|
await adminClient.realms.update(
|
|
|
|
{ realm: "master" },
|
|
|
|
{ ...masterRealm, accountTheme: "keycloak.v3" },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:34:54 +00:00
|
|
|
export async function importRealm(realm: RealmRepresentation) {
|
|
|
|
await adminClient.realms.create(realm);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteRealm(realm: string) {
|
|
|
|
await adminClient.realms.del({ realm });
|
|
|
|
}
|