Error when initializing example project
See original GitHub issueIssue Description
Hello!
really good project, i love keycloak and fastapi 😃. Unfortunately I am not able to get it running and I guess this is due to a bug:
The error happens, when I the token is decoded:
PS C:\Users\User\Desktop\KeyCloakFastAPI> python .\app.py
{'exp': 1649355552, 'iat': 1649355252, 'jti': '51e67522-19f7-45b0-9894-e862b440106b', 'iss': 'http://localhost:8085/auth/realms/Test', 'sub': '33b940e2-0bdb-49a7-9356-e6e230f49619', 'ty
p': 'Bearer', 'azp': 'admin-cli', 'acr': '1', 'scope': 'profile email', 'clientId': 'admin-cli', 'clientHost': '172.23.0.1', 'email_verified': False, 'preferred_username': 'service-acco
unt-admin-cli', 'clientAddress': '172.23.0.1'}
I my token I don´t have "resource_access, which leads to “None” and to a follow up error:
AttributeError: ‘NoneType’ object has no attribute ‘get’
traceback:
Traceback (most recent call last):
File ".\app.py", line 7, in <module>
idp = FastAPIKeycloak(
File "C:\Users\User\anaconda3\lib\site-packages\fastapi_keycloak\api.py", line 129, in __init__
self._get_admin_token() # Requests an admin access token on startup
File "C:\Users\User\anaconda3\lib\site-packages\fastapi_keycloak\api.py", line 292, in _get_admin_token
self.admin_token = response.json()['access_token']
File "C:\Users\User\anaconda3\lib\site-packages\fastapi_keycloak\api.py", line 159, in admin_token
if not decoded_token.get('resource_access').get('realm-management') or not decoded_token.get('resource_access').get('account'):
AttributeError: 'NoneType' object has no attribute 'get'
Is there something I did wrong or is this an error in the lib?
Issue Analytics
- State:
- Created a year ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Error 'Initialize Project Area' failed when creating a ... - IBM
This error occurs when the project is created either from the out of the box or custom templates.
Read more >Error during project initialization · Issue #1 - GitHub
I use MacOS Catalina, PyCharm, and the project is being initialized inside the venv. I have no problem starting plain cookiecutter projects ......
Read more >Problem of initialization in C++ - GeeksforGeeks
Here, if the data members are initialized using the object of the class, then it will show an error.
Read more >Java Error “variable might not have been initialized” | Baeldung
This error occurs when we declare a variable without initializing it. We'll discuss this error with an example, and offer some solutions to ......
Read more >Spring boot initialization error - java - Stack Overflow
Seems to need database connection on initialization, maybe providing a database connection on application.properties file or removing this ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, that solved the issue, thank you very much. I ran into a follow up error, which gave me the following hint:
=> very good, easy to solve
As a user of your library I would expect something similar also for the first error 😃.
Well, that should obviously not happen then. I will look into it, to fix the provided example. However, we might want to fix your issue anyway, since I’m not sure how fast I can tackle this.
Could you check if the
admin-cli
service account has all realm-related roles? If you use the Keycloak web interface, you should find this at:Clients > admin-cli > Service Account Roles > Client Roles > Realm Management
. If not done yet, add all the roles to the service account. If this does not fix your issue, its probably the permissions are given but somehow do not end up as claims in your access token signed for the service account