Different authentication method for specific user

Hey,

i am planning a django web application with multiple tenants (or i call it companies).

This means that my web application is used by multiple companies. Every company could shall set their own authentication method. For example company 1 and company 2 would like to use active directory and company 3 and 4 use the default django authentication system. But the users can associated with more than one company.

I have build a little diagram:

And at this point i’m stuck.

I think the companies should “register” their domain if they would like to use another authentication method. For example company 1 have the domain xyz.de and all users in my web app with the domain in their email adress must authenticate them over the active directory from company 1.

I think the user could type only their email adress in the login form and django can check if a specific authentication method is configured for the domain. And in the next step the user can type the password or he is redirect to the other authentication system.

I have following questions:

  1. How can i implement that?
  2. Is there a better way to implement my requirements?
  3. Exist already a package that can help me?
  4. Is it possible to use multiple active directories to authenticate users from different companies?

Thanks for your help!