我在AWS cloud9中有一个项目。当我尝试通过LinkedIn或Facebook登录时,按下“允许访问”我的LinkedIn或Facebook帐户后,我收到此错误页面:
Facebook的:
LinkedIn:
追溯:
Environment:
Request Method: GET
Request URL: http://8011118167a14663bf26f276beae74fe.vfs.cloud9.us-east-2.amazonaws.com:80/complete/facebook/?redirect_state=s9F0XdwpzEpFx26DcClydCC2TI5gRICR&code=AQCHwhQV29jyqzxZ8_qtAQD6D_baKZvcdaMOL889co7q6N_rerhEvteJ3-1iE-vIhyX87qAHfCTN4XgoFF0IQT_MyWHsIf28ggfZt3IqUMXFODBsXaYY_PJJCvDRniv20gqMF9Pq1Lm2L1x-OFAOsqLsIboYZDrmG6ceFpADyzdKOXZRsy44uiXKhZIzht3VI45je8JbWowZJa-YUcRD1zY5OQnniW5ujq3IYe2l0z6nha6hq7Lk0lzLD5BR4I5O9sd7CdMxeRXX0NBmc9Qz4av2j2xsiHQq9zBASy03dSwENwQ2veIOhpQCMrIkkXwfNGQ&state=s9F0XdwpzEpFx26DcClydCC2TI5gRICR
Django Version: 1.8.4
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_social_project',
'django_social_app',
'social.apps.django_app.default',
'facebook_auth')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/usr/local/lib64/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib64/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/usr/local/lib64/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/social/apps/django_app/utils.py" in wrapper
51. return func(request, backend, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/social/apps/django_app/views.py" in complete
28. redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/social/actions.py" in do_complete
43. user = backend.complete(user=user, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/social/backends/base.py" in complete
41. return self.auth_complete(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/social/utils.py" in wrapper
232. raise AuthCanceled(args[0])
Exception Type: AuthCanceled at /complete/facebook/
Exception Value: Authentication process canceled
我看到了How to solve Authentication process canceled error?,但它不起作用。
我正在使用python Django v1.8.4。
settings.py:
import os
from config import *
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = ''
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = ''
SOCIAL_AUTH_FACEBOOK_KEY =''
SOCIAL_AUTH_FACEBOOK_SECRET = ''
SOCIAL_AUTH_FACEBOOK_OAUTH2_KEY =''
SOCIAL_AUTH_FACEBOOK_OAUTH2_SECRET = ''
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/home/'
SOCIAL_AUTH_LOGIN_URL = '/'
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 't+m0(7&y_%ek6&4r4z(4y3u31me(ld&zy*(()7fpkb2rn5ozm%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_social_project',
'django_social_app',
'social.apps.django_app.default',
'facebook_auth',
)
AUTHENTICATION_BACKENDS = (
'social.backends.linkedin.LinkedinOAuth2',
'django.contrib.auth.backends.ModelBackend',
'facebook_auth.backends.FacebookBackend',
'facebook_auth.backends.FacebookJavascriptBackend',
'social.backends.facebook.FacebookOAuth2',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'django_social_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors':[
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
],
},
},
]
WSGI_APPLICATION = 'django_social_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
urls.py
#!/usr/bin/python3
"""django_social_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url('', include('django.contrib.auth.urls', namespace='auth')),
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^$', 'django_social_app.views.login'),
url(r'^home/$', 'django_social_app.views.home'),
url(r'^logout/$', 'django_social_app.views.logout'),
url(r'^personalDetsilsForm/$', 'django_social_app.views.personalDetsilsForm'),
]
view.py
#!/usr/bin/python3
from django.shortcuts import render
from django.shortcuts import render_to_response, redirect
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
from django.template.context import RequestContext
def login(request):
#return render_to_response('login.html', context=RequestContext(request))
print('this is print: ',request)
return render(request, 'login.html')
@login_required(login_url='/')
def home(request):
return render_to_response('home.html')
def logout(request):
auth_logout(request)
return redirect('/')
# Create your views here.
def personalDetsilsForm(request):
return render_to_response('personalDetsilsForm.html')
的login.html
<body style="background-color: white; text-align: center; padding-top:10%">
<img src="https://image.ibb.co/geWcEm/gowithhh.png" style="display:block;margin:auto;padding-bottom:5%;max-width:30%;">
{% if user and not user.is_anonymous %}
<a>Hello, {{ user.get_full_name }}!</a>
<br>
<a href="/logout">Logout</a>
{% else %}
<a href="{% url 'social:begin' backend='linkedin-oauth2' %}"><button class="button" style="background-color: #0077B5;"><span>Login with Linkedin</span></button></a><br><br>
<a href="{% url 'social:begin' 'facebook' %}"><button class="button" style="background-color: #3b5998;"><span>Login with Facebook </span></button></a><br><br>
<a href="/personalDetsilsForm"><button class="button" style="background-color: #f4511e;"><span>Tell us about yourself</span></button></a><br><br>
{% endif %}
</body>