简体   繁体   中英

How do I log a user in with the Facebook API and use Django the user?

So I have been developing an application for awhile now and originally I used Django user model so I have a bunch of checks similar to

{% if request.user.is_authenticated %}

and

@login_required

in my code. Now I have just gotten Facebook login "working" after probably 2 months of fiddling with different methods of testing it, however I have some questions.

Is there a way for me to sign in a Django user when someone signs in with Facebook? That way I can use all the Django user model functionality I already have in my code.

Or am I going to have to do all those checks with the Facebook API? If so, want to give me some hints on how to do that?

Thanks.

You can customize the Users authentication .

Then autenticate when you autenticate FB login from django.contrib.auth import login

def my_fb_logon(request):
    // your user code
    ...
    if loged:
        user.backend='django.contrib.auth.backends.ModelBackend'
        login(request, user)

You'll need to manually specify the authentication backend because you're not calling authenticate() first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM