Skip to content

Instantly share code, notes, and snippets.

@maitrungduc1410
Last active December 27, 2022 03:25
Show Gist options
  • Save maitrungduc1410/b20d72be66419e9cccbd08979b29012e to your computer and use it in GitHub Desktop.
Save maitrungduc1410/b20d72be66419e9cccbd08979b29012e to your computer and use it in GitHub Desktop.
Import users from OpenEdx to Keycloak with NodeJS
import KcAdminClient from "@keycloak/keycloak-admin-client";
const kcAdminClient = new KcAdminClient({
baseUrl: "http://localhost:8080",
realmName: "myrealm",
});
const credentials = {
grantType: "password",
username: "superuser",
password: "xxxxxx",
clientId: "myclient",
clientSecret: "myclientsecret",
};
await kcAdminClient.auth(credentials);
const user = await kcAdminClient.users.create({
username: "openedxuser1",
email: 'openedxuser1@gmail.com',
emailVerified: true,
firstName: "AAAAA",
lastName: "BBBBB",
enabled: true,
credentials: [
{
type: 'password',
credentialData: "{\"hashIterations\": 150000,\"algorithm\": \"pbkdf2-sha256\"}",
secretData: "{\"salt\": \"eGl5VFUzTDVHbFlI\",\"value\": \"Y+tlU1BH10IDYMycH5+4S8J3IoeakcGKjKS51jDxcEQ=\"}",
}
]
})
console.log(user)
@maitrungduc1410
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment