nodejs should be installed
Create a folder and node project:
mkdir keycloak-admin
cd keycloak-admin
npm init -y
Add the keycloak-admin
package:
npm add keycloak-admin -D
create a script:
vim index.js
Add the following code:
#!/usr/bin/env node
const KcAdminClient = require('keycloak-admin').default;
const adminClient = new KcAdminClient({
baseUrl: "http://localhost:8180/auth",
realmName: 'master',
});
(async () => {
await adminClient.auth({
username: 'admin',
password: 'admin',
grantType: 'password',
clientId: 'admin-cli',
});
const user = await adminClient.users.create({
username: "test",
email: '[email protected]',
enabled: true,
});
console.log("user created:", user);
})();
Then execute:
chmod +x index.js
./index.js