-
Notifications
You must be signed in to change notification settings - Fork 308
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 import name 'Keycloak' from 'keycloak' #559
Comments
Capture of the Keycloak folder with the init.py file Contents of file -- coding: utf-8 --Copyright (C) 2017 Marcos Pereira [email protected]This program is free software: you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU Lesser General Public License for more details.You should have received a copy of the GNU Lesser General Public Licensealong with this program. If not, see http://www.gnu.org/licenses/.from .keycloak_admin import * |
You're referencing code here from different packages called |
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
# Configure client
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 <module>
token = keycloak_openid.token("user_id", "userPw")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program
Files\Python312\Lib\site-packages\keycloak\keycloak_openid.py", line 319,
in token
return raise_error_from_response(data_raw, KeycloakPostError)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program
Files\Python312\Lib\site-packages\keycloak\exceptions.py", line 192, in
raise_error_from_response
raise error(
keycloak.exceptions.KeycloakPostError: 400:
b'{"error":"invalid_client","error_description":"Parameter
client_assertion_type is missing"}'
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
<#559 (comment)>,
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')
<end_code>
I need to get a TOKEN from keycloak to authenticate to an API server.
any help would be appreciated. It looks like many people are doing it, but I cannot get around the import issue.
The text was updated successfully, but these errors were encountered: