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

IntegrityError: null value in column "email" violates not-null constraint #38

Closed uw-rvitorino closed 1 year ago

uw-rvitorino commented 2 years ago

Describe the bug IntegrityError django_keycloak.middleware in append_user_info_to_request error null value in column "email" violates not-null constraint

django_keycloak/middleware.py in append_user_info_to_request (line 39) raises this error when the user_info does not contain the email property (because the Token is not valid anymore)

To Reproduce Steps to reproduce the behavior:

  1. Login with your credentials in a UI calling a Django API served by this library
  2. Remain in the UI and allow your token to expire
  3. Click somewhere that calls the Django API
  4. See error crashing the Django project

Expected behavior The middleware should try to get the email from the user info but if it's None it should return an Unauthorised response and not try to save the user info,

Screenshots Screenshot 2022-10-20 at 18 22 12

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context N/A

moritz89 commented 2 years ago

Ah yes, we would probably use a raise_on_error function to check the responses of all Keycloak calls. Basically everywhere requests.request() is called

moritz89 commented 2 years ago

Could you test if this issue still persists in the v2 branch. AFAIK, this has been solved

moritz89 commented 2 years ago

@uw-rvitorino Have you been able to check if the bug still persists in the v2 release?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 7 days with no activity.