问题
I am using django-allauth library to integrate Facebook login into my website (on localhost). The problem is the following: when I have finished setting everything up and I try to click on my Facebook login button, nothing occurs at all. On hover, the browser shows the following link on the Facebook login button:
allauth.facebook.login('', 'authenticate', 'login', '')
I have the following code.
In settings.py:
ALLOWED_HOSTS = [
'127.0.0.1',
'localhost',
]
INSTALLED_APPS = [
...
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
]
...
...
...
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"accounts.backends.EmailAuthenticationBackend",
"allauth.account.auth_backends.AuthenticationBackend",
]
SITE_ID=1
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'}}
In urls.py (general project urls, however I tried to set this for accounts.urls separately, to no avail either):
urlpatterns = [
...
path('', include('accounts.urls')),
path('accounts/', include('allauth.urls')),
path('admin/', admin.site.urls),
]
In signup.html:
{% load socialaccount %}
{% providers_media_js %}
...
<a class="facebook-login" href="{% provider_login_url "facebook" method="js_sdk" %}">
<i class="ion-logo-facebook"></i>
<div>Sign up with Facebook</div>
...
I have tried reconfiguring the template by setting method to oauth2 instead of js_sdk, but again nothing works. The button just seems to do nothing.
On Facebook Developers, I have set localhost as my app domain. Also, I have configured everythin in Django admin, with localhost set to bear Facebook login. And yes, I am running the server with http://localhost:8000/.
Could anyone help me understand what I am missing? Maybe I should create a new view for Facebook login and I don't really get it?
回答1:
The places i can see the problem come from are
1) In the SOCIALACCOUNT_PROVIDERS in your settings py. you didn't specify the app config below
'APP': {
'client_id': '123',
'secret': '456',
'key': ''
}
into your project. with the secret and client id the ones from facebook.
2) setting up the callback URL in your Facebook settings
3) Also so far, it is oauth2 that is the most used convention
social media authentication is not complicated, it starts getting complicated when working on a rest api. in case the solutions do not work let me know.
来源:https://stackoverflow.com/questions/60135230/django-allauth-facebook-login-button-wouldnt-do-anything