Hi everyone,
I want to use the keycloak-admin-client to write a simple app to add users to my Keycloak. The keycloak is running on a remote URL and I want to develop from localhost. I am constantly getting:
Access to XMLHttpRequest at 'https://auth.keycloakserver.biz/auth/admin/realms/Test/users' from origin 'https://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I use code similar to the following except:
import KcAdminClient from "@keycloak/keycloak-admin-client";
[...]
const kcAdminClient = new KcAdminClient();
try {
const kcAdminClient = new KcAdminClient(
{
baseUrl: 'https://auth.keycloakserver.biz/auth',
realmName: 'Test',
}
);
await kcAdminClient.auth({
username: 'testadmin',
password: 'testadmin',
grantType: 'password',
clientId: 'admin-cli',
});
// List all users
const users = await kcAdminClient.users.find();
console.log(users);
} catch (error) {
console.log(error)
}
Calling kcAdminClient.auth() is no problem. I added the WebOrigins to the admin-cli client. Just kcAdminClient.users.find(); produces the CORS error on the REST API. Any suggestion if this is fixable and how to fix this?
I was successfully able to use python-keycloak ยท PyPI but why implement a backend that just forwards the same data when I can directly do everything in JS. I would really appreciate some feedback on how to fix the JS admin client
Thanks in advance,
Domi