Skip to content

Two factor not working with django-auth-adfs #694

@hrebynakha

Description

@hrebynakha

Two factor not working with other authentication backend (django-auth-adfs)

Expected Behavior

I'm trying to setup 2fa for application with already configured authentication with django-auth-adfs, and have issue with using it.
Setup with QR code successfully completed, but when i log out from application and login again and try access to the views with OTPRequiredMixin it check my login and cannot process login step

  1. when the login_url configured as django_auth_adfs:login
    login_url = 'django_auth_adfs:login'
    it return error To Many redirects
  2. when the login_url configured as two_facrtort:login
    login_url = 'two_factor:login'
    it return the login form that i can't process (because user doesn't have login\password in application )

Current Behavior

When user already authenticated in application we can check this by request.user.is_authentificated and force step with auth without any input ( username \password form )

Possible Solution

Modification class LoginView, add force step auth for this class if request.user.is_authentificated is True

Steps to Reproduce (for bugs)

  1. Configure ADFS auth in application (https://github.com/snok/django-auth-adfs/tree/master)
  2. Configure django-two-factor-auth
    my settings.py looks like:
INSTALLED_APPS = [
....
    'django_auth_adfs',
.....

    'django_otp',
    'django_otp.plugins.otp_totp',
    'django_otp.plugins.otp_static',
    'two_factor',

]

MIDDLEWARE = [
......
    'django_auth_adfs.middleware.LoginRequiredMiddleware',
    'django_otp.middleware.OTPMiddleware', 
]
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django_auth_adfs.backend.AdfsBackend',

)
LOGIN_URL = "django_auth_adfs:login"
LOGIN_REDIRECT_URL = 'two_factor:profile'

  1. Log in in application and setup MFA (when I setup it first time it's works well)
  2. Logout from application
  3. Login again and try to access to view with OTPRequiredMixin and got error with ToMany redirect or got login form

Your Environment

  • Browser and version: Chrome 120.0.6099.217
  • Python version: 3.9
  • Django version: 4.2.7
  • django-otp version: 1.3.0
  • django-two-factor-auth version: 1.15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions