AllAuth debugging: social account does not register user despite successful connection

When you click the facebook login button in the login form, the fb popup window is displayed, but after entering the credentials, the popup window closes and nothing happens.

Pressing the button again without reloading the pages confirms that the fb account is connected to print in the browser:

Called by FB.login () when the user is already connected.

However, new entries do not appear in the user database, the user is not redirected and does not log into the system. So the problem is with the way AllAuth handles things. There is no debugging information appearing anywhere in the background, although this is somewhat difficult to understand.

Here's the settings for allauth:

LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/' DEFAULT_FROM_EMAIL = "[removed for stackoverflow]" ACCOUNT_EMAIL_REQUIRED = True SOCIALACCOUNT_EMAIL_REQUIRED = True ACCOUNT_UNIQUE_EMAIL = True ACCOUNT_EMAIL_VERIFICATION = 'mandatory' SOCIALACCOUNT_EMAIL_VERIFICATION = "mandatory" SOCIALACCOUNT_QUERY_EMAIL = True SOCIALACCOUNT_PROVIDERS = \ {'facebook': {'METHOD': 'oauth2', 'SCOPE': ['email','public_profile', 'user_friends'], 'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, 'FIELDS': [ 'id', 'email', 'name', 'first_name', 'last_name', 'verified', 'locale', 'timezone', 'link', 'updated_time'], 'EXCHANGE_TOKEN': True, 'VERIFIED_EMAIL': False, 'VERSION': 'v2.4'}} 

and this is js on the login page:

 <script> window.fbAsyncInit = function() { FB.init({ appId : '[removed for stackoverflow]', xfbml : true, version : 'v2.10' }); FB.AppEvents.logPageView(); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> 
+5
source share
1 answer

Django-allauth Facebook Login

Install django-allauth first

 $(venv) pip3 install django-allauth 

now put this code in your installed applications in settings.py

 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.facebook', 

Also, put the code below in settings.py

 AUTHENTICATION_BACKENDS = ( 'allauth.account.auth_backends.AuthenticationBackend', 'django.contrib.auth.backends.ModelBackend', ) 

Also put them in settings.py

 SOCIALACCOUNT_PROVIDERS = \ {'facebook': {'METHOD': 'oauth2', 'SCOPE': ['email','public_profile', 'user_friends'], 'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, 'FIELDS': [ 'id', 'email', 'name', 'first_name', 'last_name', 'verified', 'locale', 'timezone', 'link', 'gender', 'updated_time'], 'EXCHANGE_TOKEN': True, 'LOCALE_FUNC': lambda request: 'kr_KR', 'VERIFIED_EMAIL': False, 'VERSION': 'v2.4'}} 

The identifier and key can be found in https://developers.facebook.com/ create an application and go to DashBoard, you will see your

 #facebook SOCIAL_AUTH_FACEBOOK_KEY = 'secret!' # App ID SOCIAL_AUTH_FACEBOOK_SECRET ='secret!' #app key 

You might want to add this

 LOGIN_REDIRECT_URL = "/" #if you succeed in login, you'll be redirected to the main page. 

Now we need to change urls.py Add this code to urlpatterens

 url(r'^accounts/',include('allauth.urls')), 

Now go back to https://developers.facebook.com/ go to settings, click "Add Platform", click the website, put http: // localhost: 8000 / and click the quick launch button. go ahead and do what dev.facebook drives.

Now you need to set your site id in settings.py

 #site id SITE_ID = <your local host site id> #ie http://localhost:8000 # for the dev mode, you need to use localhost id facebook does not support the name 127.0.0.1:8000 #little options for your page signup. ACCOUNT_EMAIL_REQUIRED=True 

We need to register our site ID and social application in our django admin. First, migrate and runerver

 $(venv) python3 manage.py migrate 

go to http: // localhost: 8000 / admin / and click the site ID change example.com to http: // localhost: 8000 (if you are already at the production level, you can just use your IP addresses or domain).

enter image description here

After saving the application, we are ready to log in using facebook. Put these template tags at the top of the html where you want your users to be logged in.

 {% load socialaccount %} {% providers_media_js %} 

and you can write this exact position where you want to make the login button

 <a href="{% provider_login_url "facebook" method="js_sdk" %}">Login Button image</a> 

This will send your request to the account / login page that processes your login procedures.

Link: https://medium.com/@jinkwon711/django-allauth-facebook-login-b536444cbc6b

+5
source

Source: https://habr.com/ru/post/1271430/


All Articles