Open bmorse526 opened 2 months ago
Capture of the Keycloak folder with the init.py file
Contents of file
#
#
#
#
from .keycloak_admin import from .keycloak_openid import
You're referencing code here from different packages called keycloak-client
and keycloak
. This is a project for the package python-keycloak
. If you wish to use python-keycloak
, make sure only python-keycloak
package is installed an d no other is used as keycloak-client
or keycloak
don't work well together with python-keycloak
. Then I'd suggest to follow our getting started guide for OIDC client https://python-keycloak.readthedocs.io/en/latest/modules/openid_client.html
Thank you. That layed out more than I have found.
I have removed all libraries for keycloak and only re-installed python-keycloak. Using the reference you provided I have this code.
from keycloak import KeycloakOpenID
keycloak_openid = KeycloakOpenID(server_url="https://xx.yy.com/kc/", client_id="client_id", realm_name="realm", client_secret_key="shush", verify=False)
token = keycloak_openid.token("user", "userPw")
userinfo = keycloak_openid.userinfo(token['access_token'])
I am getting this error
Traceback (most recent call last):
File "c:\filepath\API\KeyCloak try 3.py", line 26, in
I am not sure where to go from there. I have a client and a user set up in keycloak as it appears the token code needs a user id and PW. I would prefer using the client entry with its secret key to get a token, but have not found a way in the documentation to do it. I appreciate any help or direction you could provide. I am after getting a bearer token for use in an API header call (Authorization: Bearer asdfjkaskhfskdfksahf )
On Thu, May 9, 2024 at 1:12 PM Richard Nemeth @.***> wrote:
You're referencing code here from different packages called keycloak-client and keycloak. This is a project for the package python-keycloak. If you wish to use python-keycloak, make sure only python-keycloak package is installed an d no other is used as keycloak-client or keycloak don't work well together with python-keycloak. Then I'd suggest to follow our getting started guide for OIDC client https://python-keycloak.readthedocs.io/en/latest/modules/openid_client.html
— Reply to this email directly, view it on GitHub https://github.com/marcospereirampj/python-keycloak/issues/559#issuecomment-2103344937, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTA4VTVC6CQ7PSO5YW4E63ZBPKB7AVCNFSM6AAAAABHPNE3TGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBTGM2DIOJTG4 . You are receiving this because you authored the thread.Message ID: @.***>
Sorry had a typo in the code. (user name) after correcting it I get
File "c:\Users\bob.morse\Documents\Python\API\KeyCloak try 3.py", line 26, in
Sorry for the bad previous post
The end state I need is a Authorization: Bearer token. Once the token is returned is that the token object or is it a property of the token object?
Full error message: ImportError: cannot import name 'Keycloak' from 'keycloak' (C:\Program Files\Python312\Lib\site-packages\keycloak__init__.py) Python 3.12
keycloak-client 0.15.4 (currently) have tried keycloak 1.15 with same error
VS Code for IDE (Have tried Python native IDE with same error
I have uninstalled any version of keycloak and made sure there was only 1.
I have tried Keycloak and keycloak neither work. I have copied code snippets from multiple sites and other that variable names the content matches.
from keycloak import keycloak kc = keycloak.Keycloak(server_url="https://xx.yy.com/kc/auth/", verify=False) response = kc.token(client_id='me', client_secret='shush')