Django Multiple Authentication Backend for one project, HOW?

后端 未结 4 1837
野性不改
野性不改 2020-12-05 00:52

Need serious help here.

I have an application written in django/python and I have to extend it and include some other solution as an \"app\" in this application. For

4条回答
  •  天命终不由人
    2020-12-05 01:30

    Using Multiple AUTHENTICATION BACKENDS is very easy, you just need to add this to settings.py

    AUTHENTICATION_BACKENDS = (
        'social_core.backends.open_id.OpenIdAuth',
        'social_core.backends.google.GoogleOpenId',
        'social_core.backends.google.GoogleOAuth2',
        'social_core.backends.google.GoogleOAuth',
        'social_core.backends.facebook.FacebookOAuth2',
        'django.contrib.auth.backends.ModelBackend',
    )
    

    and this may create a problem at signup page so add a login argument in your signup view in views.py file like this login(request, user, backend='django.contrib.auth.backends.ModelBackend')

    def signup_view(request):
        if request.method=='POST':
            form = UserCreationForm(request.POST)
            if form.is_valid():
                user=form.save()
                login(request, user, backend='django.contrib.auth.backends.ModelBackend')
                return redirect('home')
    

提交回复
热议问题