Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when initializing example project

See original GitHub issue


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 .\
{'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': '', 'email_verified': False, 'preferred_username': 'service-acco
unt-admin-cli', 'clientAddress': ''}

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 (most recent call last):
  File ".\", line 7, in <module>
    idp = FastAPIKeycloak(
  File "C:\Users\User\anaconda3\lib\site-packages\fastapi_keycloak\", 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\", line 292, in _get_admin_token
    self.admin_token = response.json()['access_token']
  File "C:\Users\User\anaconda3\lib\site-packages\fastapi_keycloak\", 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:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

Coding-Crashkursecommented, Apr 8, 2022

Ok, that solved the issue, thank you very much. I ran into a follow up error, which gave me the following hint:

AssertionError: The access required was not contained in the access token for the `admin-cli`.
                                 Possibly a Keycloak misconfiguration. Check if the admin-cli client has `Full Scope Allowed`
                                 and that the `Service Account Roles` contain all roles from `account` and `realm_management`

=> very good, easy to solve

As a user of your library I would expect something similar also for the first error 😃.

yannicschroeercommented, Apr 8, 2022

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

Read more comments on GitHub >

github_iconTop 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 file or removing this ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found