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

Fix middleware unbound variable bug & New option for token prefix #48

Closed diogosilva30 closed 1 year ago

diogosilva30 commented 1 year ago

Currently, the middleware has a bug when checking for authentication type. If user tries to use an authentication different from basic or Bearer (e.g. JWT) we have an unbound variable token error. This PR fixes this issue by creating a new config variable for the user to specify the token prefix that should be expected (still defaults to Bearer), but adds more flexibility. If the auth type is not basic or the user-specified token prefix a None value is returned, fixing the unbound variable error.

Also, a small fix in the admin was made. When registering our model into model admin, I've added a try catch, in case the AUTH_USER_MODEL has already been registered (the user can have multiple auth systems all trying to register an auth user admin).

diogosilva30 commented 1 year ago

@moritz89 Can you approve PR?