Trying to Get Example to Work

I am new to keycloak and am having trouble with the example client. Here is my python code:

from keycloak.realm import KeycloakRealm

realm = KeycloakRealm(server_url=‘https://auth.******.’, realm_name=‘jasonrealm’)

oidc_client = realm.open_id_connect(client_id=‘jason-test-client’,
client_secret=‘*********’)
creds = oidc_client.client_credentials()
print(creds)

admin_client = realm.admin
root = admin_client.root()

The error I get is as follows:

File “keystore-client1.py”, line 9, in
creds = oidc_client.client_credentials()
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/openid_connect.py”, line 216, in client_credentials
return self._token_request(grant_type=‘client_credentials’, kwargs)
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/openid_connect.py”, line 296, in _token_request
return self._realm.client.post(self.get_url(‘token_endpoint’),
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/openid_connect.py”, line 36, in get_url
return self.well_known[name]
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/well_known.py”, line 35, in getitem
return self.contents[key]
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/well_known.py”, line 27, in contents
self._contents = self._realm.client.get(self._path)
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/client.py”, line 74, in get
return self._handle_response(
File “/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/client.py”, line 89, in _handle_response
raise KeycloakClientError(original_exc=err)
keycloak.exceptions.KeycloakClientError: 404 Client Error: Not Found for url: https://auth.
****./auth/realms/jasonrealm/.well-known/openid-configuration

I am really disappointed the example did not work. Any help is appreciated.

Sorry here it is formatted:

from keycloak.realm import KeycloakRealm

realm = KeycloakRealm(server_url='https://auth.*********.***', realm_name='jasonrealm')

oidc_client = realm.open_id_connect(client_id='jason-test-client', client_secret='*********') creds = oidc_client.client_credentials() print(creds)

admin_client = realm.admin root = admin_client.root()

The error I get is as follows:

File "keystore-client1.py", line 9, in creds = oidc_client.client_credentials() File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/openid_connect.py", line 216, in client_credentials return self._token_request(grant_type='client_credentials', **kwargs) File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/openid_connect.py", line 296, in _token_request return self._realm.client.post(self.get_url('token_endpoint'), File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/openid_connect.py", line 36, in get_url return self.well_known[name] File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/well_known.py", line 35, in __getitem__ return self.contents[key] File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/well_known.py", line 27, in contents self._contents = self._realm.client.get(self._path) File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/client.py", line 74, in get return self._handle_response( File "/home/jason/anaconda3/lib/python3.8/site-packages/keycloak/client.py", line 89, in _handle_response raise KeycloakClientError(original_exc=err) keycloak.exceptions.KeycloakClientError: 404 Client Error: Not Found for url: https://auth.*********.***/auth/realms/jasonrealm/.well-known/openid-configuration

I am really disappointed the example did not work. Any help is appreciated.

Looks like the keycloak lib still expects the old keycloak urls (with auth prefix) while your keycloak server is a newer version (>=18) that does not use this prefix by default.

Looking at the code, it seem like the /auth is coing from your config…

We are using version 20 something at the server. In the client I am working with, jason-test-client, I removed the …/auth from the Root URL in the admin console and got the same error. I am using python-keycloak-client v 2.3.0.

Where in the code does the config happen? Our configuration is in the Admin Console. Is there more that needs to be done?

Any other ideas here? It is keeping us from running Keycloak.