urbanplatform / django-keycloak-auth

Middleware to allow authorization using Keycloak and Django for django-rest-framework (DRF). This package should only be used in projects starting from scratch, since it overrides the users' management.
MIT License
32 stars 14 forks source link

How does logging work? #25

Closed Wissperwind closed 2 years ago

Wissperwind commented 2 years ago

Hi,

I configured the keykloak settings and tried to login into the admin area. The log in was refused. Nothing was printed from django. How do I debug this? Is there a switch to enable debug prints?

moritz89 commented 2 years ago

Currently there is no debug logic. Therefore, I would recommend using debugpy with VS Code or simply import ipdb; ipdb.set_trace() for something quick and dirty. As a reference, these are the settings I use:

# env file
KEYCLOAK_SERVER_URL=http://localhost:8080
KEYCLOAK_INTERNAL_URL=http://localhost:8080
KEYCLOAK_REALM=some-realm
KEYCLOAK_CLIENT_ID=my-client
KEYCLOAK_CLIENT_SECRET_KEY=3135d8ba-1d81-11ed-a9d0-23394d9740b5

# django settings.py
KEYCLOAK_CONFIG = {
    "SERVER_URL": os.getenv("KEYCLOAK_SERVER_URL"),
    "INTERNAL_URL": os.getenv("KEYCLOAK_INTERNAL_URL"),
    "REALM": os.getenv("KEYCLOAK_REALM"),
    "CLIENT_ID": os.getenv("KEYCLOAK_CLIENT_ID"),
    "CLIENT_SECRET_KEY": os.getenv("KEYCLOAK_CLIENT_SECRET_KEY"),
    "CLIENT_ADMIN_ROLE": "admin",
    "REALM_ADMIN_ROLE": "admin",
    "EXEMPT_URIS": [],
    "DECODE_TOKEN": os.getenv("KEYCLOAK_DECODE_TOKEN", "False").lower() in ("true", "1", "t"),
}
Wissperwind commented 2 years ago

Ok, I debugged a bit. I think in keykloak.py in the method is_token_active would a debug switch make sense. In case of activation it could print introspect_token what would give valuable information about the configuration. For Example: {'error': 'invalid_request', 'error_description': 'Client not allowed.'}

rjvitorino commented 2 years ago

I will try to improve the documentation of configuring accounts with the library and Keycloak, either on the README or on the project's wiki. It won't solve the Debug request, but it helps with the onboarding process.

moritz89 commented 2 years ago

Logging has explicitly been added to the upcoming v2 with an example in the test_site/settings.py file