Unable to get Linkedin auth to work with django-social-auth

末鹿安然 提交于 2020-01-03 19:38:12

问题


I am trying to configure Linkedin auth on my Django website. I use django-social-auth I follow the steps mentioned in the Docs. I have been stuck on this for quite some time.

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')),

And in my Template

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

I get Error

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

  Please try again Home

回答1:


These are the settings i used for 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



回答2:


You should try testing on the same domain as application is configured.

Register API KEY for domain like test123.youworkserevr.com and put in you hosts file:

127.0.0.1       test123.youworkserevr.com

Try access for you app via test123.youworkserevr.com (instead of 127.0.0.1 or localhost)



来源:https://stackoverflow.com/questions/12853038/unable-to-get-linkedin-auth-to-work-with-django-social-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!