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
linkedin
I get Error
Error!
Sorry but some error made you impossible to login.
Please try again Home
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
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)
Related
I've set up social-auth-app-django in production. But after facebook redirect I got AuthCanceled and still unable to get it work.
In my user model email address used to sign up. This is my user model:
class User(AbstractUser):
email = models.EmailField(_('email address'), unique=True)
avatar = models.ImageField(blank=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
in settings.py:
MIDDLEWARE = [
...
'social_django.middleware.SocialAuthExceptionMiddleware',
]
TEMPLATES = [
...
'context_processors': [
...
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2',
'accounts.backends.ModelBackend'
)
LOGIN_URL = '/'
LOGOUT_URL = '/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
SOCIAL_AUTH_FACEBOOK_KEY = '..' # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = '...' # App Secret
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'id,name,email',
}
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
Valid OAuth redirect URIs in facebook login app: https://example.com/oauth/complete/facebook/
Thank you for your time and help.
For those landing on this question, after discussing the topic with OP via email, the problem was caused by an incorrect build of redirect_uri when exchanging the code for an access_token.
The incorrect build of this URI was caused because the Django backend sits behind Nginx, but the proper headers were not passed to it (X-Forwarded-For and Host), so Django was unaware of the right host it was services requests as, in the end, the URLs were pointing to localhost instead of the intended domain.
For me everything is working like a charm: Facebook, Google, Twitter and github.
This may be a configuration problem.
Here's how I've setup everything (note: I'm in developer mode in Facebook, but it works fine with my 2 accounts), I hope this can help:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
'compressor',
'app',
)
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
)
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.github.GithubOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
# https://simpleisbetterthancomplex.com/
# tutorial/2016/10/24/how-to-add-social-login-to-django.html
SOCIAL_AUTH_GITHUB_KEY = 'xxx'
SOCIAL_AUTH_GITHUB_SECRET = 'xxx'
SOCIAL_AUTH_TWITTER_KEY = 'xxx'
SOCIAL_AUTH_TWITTER_SECRET = 'xx'
SOCIAL_AUTH_FACEBOOK_KEY = 'xxxx'
SOCIAL_AUTH_FACEBOOK_SECRET = 'xxx'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'name, email, age_range'
}
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'xxx'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'xxx'
i dont know also what the difference between
https://example.com/oauth/complete/facebook/
and
https://example.com/social-auth/complete/facebook/
in my case i included both and it worked
I searched many days to solve this problem. My solution is that the authentication need to SSL, so you should install ssl and use runsslserver instead of runserver. if you are already using https or after made, you need to add this commend - SOCIAL_AUTH_REDIRECT_IS_HTTPS = True in settings.py. In my case, I'm using https already, so I solved this problem just adding that code.
I'm struggling to set up django-social-auth on my app. Whenever I hit http://<* domain here *>/social/login/twitter/ I get an error page saying 'Incorrect authentication service "twitter"' with the exception "WrongBackend".
Here are is my settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
<* omitted code *>
'social_auth',
)
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'django.contrib.auth.backends.ModelBackend',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
<* omitted code *>
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_login_redirect',
)
LOGIN_URL = '/auth/login/'
LOGIN_REDIRECT_URL = '/account/'
LOGIN_ERROR_URL = '/auth/login/error/'
TWITTER_CONSUMER_KEY = '<* omitted code *>'
TWITTER_CONSUMER_SECRET = '<* omitted code *>'
and my URLs
urlpatterns = patterns('',
<* omitted code *>
url(r'social/', include('social_auth.urls')),
)
Am I missing anything obvious on this one?
I've setup allauth according to the readme. syncdb'ed etc.
However when i try to setup a social app in admin the Provider dropdown is empty.
I've tried to print get_list() in the providers/init.py file (which I assume is the method being used by models.py & the as_choices() method.
Do you have any pointers as to where I'm doing wrong? :)
Any help is greatly appreciated.
Kind regards,
pete
my settings file(well most of it):
from os.path import abspath, basename, dirname, join, normpath
DJANGO_ROOT = dirname(dirname(abspath(__file__)))
SITE_NAME = basename(DJANGO_ROOT)
SITE_ROOT = dirname(DJANGO_ROOT)
sys.path.append(SITE_ROOT)
sys.path.append(normpath(join(DJANGO_ROOT, 'apps')))
sys.path.append(normpath(join(DJANGO_ROOT, 'libs')))
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#Authentication/signup backend
'project.apps.allauth',
'project.apps.allauth.account',
'project.apps.allauth.socialaccount',
'project.apps.allauth.socialaccount.providers.facebook',
'django.contrib.admin',
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.contrib.auth.context_processors.auth',
'project.apps.allauth.account.context_processors.account',
'project.apps.allauth.socialaccount.context_processors.socialaccount',
)
ACCOUNT_ADAPTER = 'project.apps.allauth.account.adapter.DefaultAccountAdapter'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_PASSWORD_MIN_LENGTH = 8
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = False
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False
SOCIALACCOUNT_PROVIDERS = {'facebook': {'SCOPE': ['email'], 'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, 'METHOD': 'js_sdk', 'LOCALE_FUNC': 'path.to.callable'}}
my urls file:
urlpatterns = patterns('',
#(r'^/$', include('project.apps.main.urls')),
#(r'^account/$', include('project.apps.account.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^registration/', include('project.apps.allauth.urls')),
)
I am not sure if this is the cause of your problem, but you appear to be running with a manually tweaked Python path: you placed allauth below project.apps. This may introduce weirdness, for example, think about what happens when allauth starts importing itself: "from allauth import ...". In your case, the same module/code is reachable via project.apps and via allauth directly. Please try "normalizing" your installation, preferably using a tool like virtualenv.
I am using django socialauth of OMAB, I am using the example works next to the file have not changed anything, but I put it in local_settings.py:
TWITTER_CONSUMER_KEY = 'Mk' this is no real
TWITTER_CONSUMER_SECRET = 'MTw' this is no real
FACEBOOK_APP_ID = ''
FACEBOOK_API_SECRET = ''
LINKEDIN_CONSUMER_KEY = ''
LINKEDIN_CONSUMER_SECRET = ''
ORKUT_CONSUMER_KEY = ''
ORKUT_CONSUMER_SECRET = ''
GOOGLE_OAUTH2_CLIENT_ID = ''
GOOGLE_OAUTH2_CLIENT_SECRET = ''
SOCIAL_AUTH_CREATE_USERS = True
SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False
SOCIAL_AUTH_DEFAULT_USERNAME = 'socialauth_user'
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
LOGIN_ERROR_URL = '/login/error/'
#SOCIAL_AUTH_USER_MODEL = 'app.CustomUser'
SOCIAL_AUTH_ERROR_KEY = 'socialauth_error'
GITHUB_APP_ID = ''
GITHUB_API_SECRET = ''
FOURSQUARE_CONSUMER_KEY = ''
FOURSQUARE_CONSUMER_SECRET = ''
this is my settings.py
from os.path import abspath, dirname, basename, join
try:
import social_auth
except ImportError:
import sys
sys.path.insert(0, "..")
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ROOT_PATH = abspath(dirname(__file__))
PROJECT_NAME = basename(ROOT_PATH)
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db',
}
}
TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
MEDIA_ROOT = ''
ADMIN_MEDIA_PREFIX = '/admin-media/'
MEDIA_URL = ''
SECRET_KEY = 't2eo^kd%k+-##ml3#_x__$j0(ps4p0q6eg*c4ttp9d2n(t!iol'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'example.urls'
TEMPLATE_DIRS = (
join(ROOT_PATH, 'templates')
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'social_auth',
'app',
)
SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'google-oauth', 'facebook', 'twitter')
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.google.GoogleOAuthBackend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.google.GoogleBackend',
'social_auth.backends.yahoo.YahooBackend',
'social_auth.backends.contrib.linkedin.LinkedinBackend',
'social_auth.backends.contrib.flickr.FlickrBackend',
'social_auth.backends.OpenIDBackend',
'social_auth.backends.contrib.livejournal.LiveJournalBackend',
'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_type_backends',
)
LOGIN_REDIRECT_URL = '/'
try:
from local_settings import *
except:
pass
I have the same problem as the user tries to rename local_settings.py to local_settings_template.py and does not work and vice versa. This user does not know how to resolved this problem, do not know how to contact you to ask. if someone could test the sample to see if has the same problem would help me a lot.
I was able to get twitter working with the following modifications
settings.py:
AUTHENTICATION_BACKENDS = (
'social_auth.backends.google.TwitterBackend',
)
SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter',)
TWITTER_CONSUMER_KEY = 'xxx'
TWITTER_CONSUMER_SECRET = 'yyy'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_auth',
)
urls.py:
url(r'', include('social_auth.urls')),
Of course this is needed:
% python manage.py syncdb
To test this directly with Twitter (without configuring any other pieces of your project/application), simply browse to /login/twitter and you should go through the authentication dance, your user will be added to the database and you'll be redirected (to a non-existent URL, but you'll have the user information).
From there you should be able to get it working with your system.
I have static.serve setup on my local development server, but it seems to cache static files (in my case, css, javascript and images) until I restart the the server. I am not using apache, and I have the cache set to:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
Removing the caches declaration all together doesn't seem to help either.
This didn't happen before I upgraded to 1.2.5 from an older 1.1 version.
It's a pain to have to restart the dev server every time (either by touching a python file or via the command line) every time I make a style update.
Edit - as suggested, I've added settings.py and url.py
Settings.py
# Django settings for zeiss_elearning project.
from django.utils.translation import ugettext_lazy as _
gettext = lambda s: s
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Jason Roy', '###'),
)
#Email settings
EMAIL_HOST = '###'
EMAIL_HOST_USER = 'info#btbcreative.com'
EMAIL_HOST_PASSWORD = '####'
DEFAULT_FROM_EMAIL = 'info#btbcreative.com'
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE' : 'django.db.backends.mysql',
'NAME' : '###',
'USER' : '###',
'PASSWORD' : '###',
'HOST' : '/Applications/MAMP/tmp/mysql/mysql.sock',
}
}
TIME_ZONE = 'America/Tijuana'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
MEDIA_DEBUG_DOC_ROOT = '/Users/jason/Bird Takes Bear/Projects/Carl Zeiss/site 2.0/media'
MEDIA_ROOT = '/Users/jason/Bird Takes Bear/Projects/Carl Zeiss/site 2.0/media'
MEDIA_URL = '/static_files/'
ADMIN_MEDIA_PREFIX = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '####'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.media.PlaceholderMediaMiddleware',
#'django.middleware.cache.FetchFromCacheMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
)
ROOT_URLCONF = 'zeiss_elearning.urls'
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'cms.context_processors.media',
)
TEMPLATE_DIRS = (,
'/Users/jason/Bird Takes Bear/Projects/Carl Zeiss/site 2.0/templates',
'/Users/jason/Bird Takes Bear/Projects/Carl Zeiss/site 2.0/cms/templates',
)
SESSION_COOKIE_AGE = 86400
LOGIN_URL = '/membership/login/'
LOGIN_REDIRECT_URL = "/"
AUTHENTICATION_BACKENDS = (
'zeiss_elearning.shared.email_auth.EmailBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_PROFILE_MODULE = 'membership.UserProfile'
FORCE_SCRIPT_NAME = ''
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'cms',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins.snippet',
'cms.plugins.googlemap',
'cms.plugins.zeiss_video',
'cms.plugins.html',
'cms.plugins.quiz',
'cms.plugins.popup',
'mptt',
'publisher',
'zeiss_elearning.forms',
'zeiss_elearning.membership',
'zeiss_elearning.quiz',
'menus',
'south',
)
INTERNAL_IPS = ('127.0.0.1',)
#CMS Settings
CMS_REDIRECTS = True
CMS_MENU_TITLE_OVERWRITE = True
CMS_DBGETTEXT = False
CMS_DEFAULT_TEMPLATE = 'base.html'
CMS_ALLOW_HTML_TITLES = False
CMS_TEMPLATES = (
('base.html', _('Default')),
('cirrus.html', _('Cirrus')),
('atlas.html', _('Atlas')),
)
# Site title for your template
CMS_SITE_TITLE = 'Zeiss Cirrus'
CMS_LANGUAGE_REDIRECT = False
CMS_LANGUAGES = (
('en', gettext('English')),
)
LANGUAGES = (
('en', gettext('English')),
)
CMS_APPLICATIONS_URLS = (
('zeiss_elearning.quiz.urls', 'Quiz')
)
urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
(r'^membership/', include('zeiss_elearning.membership.urls')),
(r'^admin/', include(admin.site.urls)),
)
urlpatterns += patterns('',
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static_files/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_DEBUG_DOC_ROOT}),)
The bottom line here, based on the data provided, seems to be that your browser is caching the media files. The recommended method to resolve this is super refreshing the pages in your browser. See ALL the comments on your post.
However, If you really do not want the media files to be cached you can simply set them constantly unique names. Like so.
<link rel="stylesheet" type="text/css" href="/site_media/css/style.css?{% now "U" %}" />
Now every time the page is reloaded the filename will be a little bit different based on the unix timestamp, forcing the browser to reload it all the time.