-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot modify existing user realms #610
Comments
The same situation |
It starts from here: And occurs when you call keycloak.KeycloakAdmin.get_realm_role. |
In my case, the following helped:
I simply omitted the username and password, then added client_id and client_secret_key |
This is a consequence of changes in #566, which removed the automatic fetching of the token upon KeycloakAdmin initialization. So from then on, when you instantiate a KeycloakAdmin class, the token for communicating with Keycloak's Rest API is not fetched, until the first action call (like If you change the realm before the token is fetched, the admin class will try to fetch the token from the A simple fix for your code is to explicitly fetch the token before changing the realm: from keycloak import KeycloakAdmin
keycloak_admin = KeycloakAdmin(
server_url="https://myauthserver",
username='myadmin',
password='mypassword',
realm_name="master",
)
keycloak_admin.connection.get_token()
keycloak_admin.connection.realm_name = "mytestrealm"
keycloak_admin.get_users() |
I'm also going to add that I agree with you @bclements and @RKN01011, this is not the best UX we are experiencing right now. I think it can be easily fixed by storing the initial realm name and using that for fetching of the token in openid_connnection. Should prevent the most common pitfalls |
Actually, after going through the code again, I've just realized that this is already implemented. What you want to use is the parameter keycloak_admin = KeycloakAdmin(
server_url="https://myauthserver",
username='myadmin',
password='mypassword',
realm_name="mytestrealm",
user_realm_name="master",
)
keycloak_admin.get_users() should just work out of the box. |
Fresh install of keycloak 26.0.0. python-keycloak 4.6.2
When I run the following against an existing realm
I get
*** keycloak.exceptions.KeycloakAuthenticationError: 401: b'{"error":"invalid_grant","error_description":"Invalid user credentials"}'
But the odd thing is, if I create a realm and do anything, like get users, everything works as expected.
Why can't I access resources in my user realm?
The text was updated successfully, but these errors were encountered: