pythondjangoweb-applicationsdjango-database

Common User management for Django project ecosystem


I have been working with Django for the last few months and have built some projects in it. I was wondering whether it is possible for the distinct Django projects to share a common-use authentication and authorization project?

There is a user management portal for the internal employees where the admin can add various employees to different user roles (like a manager, etc.). I will then define in the other projects what user role can access what part of the application statically.

Additional parameters:

Until now I have looked at the Django multi-database support which can solve my user authentication problem, but there is a catch in the authorization part where the foreign key constraints cause some problems in the models

Currently, I have written a database router and am creating a user management portal for the authentication of users from a single source.


Solution

  • You could think of a microservices based architecture where 1 of your Django project will act as a user_auth microservice.

    All requests related to login, forgot password, change password, registration, etc can we routed to that Django project (user_auth) microservice. This application will create the JWT token. You can use djangorestframework-simplejwt for creating our JWT tokens.

    And you can write authentication_classes for all your other Django projects to receive, decode and understand these JWT tokens created from user_auth microservice.

    If you have a custom user model, you can have copy of the User model in every Django project and then you could keep them as managed=False everywhere except the user_auth microservice. Or you could have it as a private pip package.

    There is much more to it, but this is the basic idea. I've had many projects with this structure which are in production on a scale of few millions.