无法让Linkedin auth与django-social-auth合作

时间:2012-10-12 05:53:38

标签: django authentication linkedin

我正在尝试在我的Django网站上配置Linkedin auth。我使用django-social-auth我按照Docs中提到的步骤操作。我已经坚持了很长一段时间。

My settings.py

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'social_auth',

'mytests'
)

AUTHENTICATION_BACKENDS = ( 'social_auth.backends.contrib.linkedin.LinkedinBackend',
                            'django.contrib.auth.backends.ModelBackend',)

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.contrib.messages.context_processors.messages',
'social_auth.context_processors.social_auth_by_name_backends',
'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_login_redirect',
)

SOCIAL_AUTH_ENABLED_BACKENDS = ('linkedin',)

LINKEDIN_CONSUMER_KEY        = 'py5pspq52ypesv' #API Key
LINKEDIN_CONSUMER_SECRET     = 'OyzsrC5GqIo85z9GsWc' #Secret Key

LOGIN_REDIRECT_URL = 'checkbox'
LOGIN_ERROR_URL = '/login-error/'

SOCIAL_AUTH_COMPLETE_URL_NAME  = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'

urls.py

url(r'', include('social_auth.urls')),

在我的模板中

<a href="{% url socialauth_begin 'linkedin' %}">linkedin</a>

我收到错误

Error!
  Sorry but some error made you impossible to login.

  Please try again Home

2 个答案:

答案 0 :(得分:1)

您应该尝试在配置应用程序的同一域中进行测试。

为test123.youworkserevr.com等域名注册API KEY并输入主机文件:

127.0.0.1       test123.youworkserevr.com

通过test123.youworkserevr.com(而不是127.0.0.1或localhost)尝试访问您的应用

答案 1 :(得分:1)

这些是我用于Linkedin Auth的设置

SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.user.get_username',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
'social_auth.backends.pipeline.associate.associate_by_email'
)

LOGIN_REDIRECT_URL = '/home/'
LOGIN_ERROR_URL = '/login_error/'

TEMPLATE_CONTEXT_PROCESSORS += (
'social_auth.context_processors.social_auth_by_name_backends',
'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_login_redirect',
)

AUTHENTICATION_BACKENDS = (
'social_auth.backends.contrib.linkedin.LinkedinBackend',
'django.contrib.auth.backends.ModelBackend',
)

The SOCIAL_AUTH_ENABLED_BACKENDS, SOCIAL_AUTH_COMPLETE_URL_NAME SOCIAL_AUTH_ASSOCIATE_URL_NAME are not required