Making a project login with facebook. But it’s showing error
my localhost url — 127.0.0.1:8000/demo/index/
My code is like this
setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
'dashboard'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.join(BASE_DIR), 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends', # <--
'social_django.context_processors.login_redirect',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
STATIC_URL = '/static/'
LOGIN_URL = '/demo/login/'
LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_FACEBOOK_KEY = '184354188769721'
SOCIAL_AUTH_FACEBOOK_SECRET = 'c4d9ed712a59be2f9bb25b5368432f61'
LOGIN_URL = '/demo/login/'
LOGIN_REDIRECT_URL = '/'
url.py
url(r'^facebook/', include('social_django.urls', namespace='social')),
index.html
<a href="{% url 'social:begin' 'facebook' %}">Login with Facebook</a>
I created facebook API and set
domain – empty
site url – empty
in facebook login(plugins)
Valid OAuth redirect URIs – http://localhost:8000/_auth/facebook
Give solution wy its showing this error while login.
URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings. Make sure Client and Web OAuth Login are on and add all your app domains as Valid OAuth Redirect URIs.
2
Answers
I got the answer... I have changed the domain name(27.0.0.1:8000 www.example.com) first using this command..
sudo -i gedit /etc/hosts
and then edited in setting.py
ALLOWED_HOSTS = ["www.example.com"]
Go to your App's settings page in http://developers.facebook.com
add site url http://www.example.com:8000/
and domain name example.com
You have to set APP DOMAINS in Facebook APP settings
Go to your App’s settings page in http://developers.facebook.com
Click on the dropdown arrow on the top left (next to the name of your app) and click “Create Test App” and give it a name
In the Settings > Basic of that new Test App set the App Domains as “localhost”
check this link for more info –
Facebook App: localhost no longer works as app domain
For Oauth URL Forward – try putting only domain name