Last active
December 27, 2022 03:25
-
-
Save maitrungduc1410/b20d72be66419e9cccbd08979b29012e to your computer and use it in GitHub Desktop.
Import users from OpenEdx to Keycloak with NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Big thanks to this discussion: https://groups.google.com/g/keycloak-user/c/XgUbXJr2xsM