Django Social Auth 'Incorrect authentication service "twitter"' (WrongBackend) - django

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?

Related

Authentication process canceled

I am developing a django project.And I want to add login with facebook.But I tried days and days but everytime I get this error Authentication process canceled.Please can anyone help me?
settings.py
INSTALLED_APPS
'social_django',
MIDDLEWARE
'social_django.middleware.SocialAuthExceptionMiddleware',
context_processors
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
AUTHENTICATION_BACKENDS
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.google.GoogleOAuth',
'django.contrib.auth.backends.ModelBackend',
and other settings
SOCIAL_AUTH_RAISE_EXCEPTIONS = False
SOCIAL_AUTH_FACEBOOK_KEY = env("SOCIAL_AUTH_FACEBOOK_KEY")
SOCIAL_AUTH_FACEBOOK_SECRET = env("SOCIAL_AUTH_FACEBOOK_SECRET")
SOCIAL_AUTH_FACEBOOK_API_VERSION = '2.8'
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = env("SOCIAL_AUTH_GOOGLE_OAUTH2_KEY")
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = env("SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET")
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
LOGIN_URL="/giris"
LOGOUT_URL="/cikis"
SOCIAL_AUTH_LOGIN_ERROR_URL = '/giris'
SOCIAL_AUTH_BACKEND_ERROR_URL="/giris"
LOGIN_ERROR_URL="/giris"
SOCIAL_AUTH_LOGIN_REDIRECT_URL="/"
SOCIAL_AUTH_LOGIN_REDIRECT_URL="/"

Social-auth AuthCanceled error after redirect from facebook

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.

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

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)

django-social-auth incorrect authentication service

I was trying to use django-social-auth today, but turned out I got an error everytime I tried to login using it.
I was using the example found in its git master branch, put in my facebook keys, but when I click to login using facebook, the error "Incorrect authentication service" appears.
That also occurs in twitter and orkut logins... does anyone have any idea why that may be happening?
Thanks a lot!
Edit
Yeah, I'm sorry, I forgot to post my code.
settings.py
from os.path import abspath, dirname, basename, join
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 = '****'
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 = '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',
)
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.OpenIDBackend',
'social_auth.backends.contrib.livejournal.LiveJournalBackend',
'django.contrib.auth.backends.ModelBackend',
)
try:
from local_settings import *
except:
pass
local_settings.py
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET = ''
FACEBOOK_APP_ID = '226521154024720'
FACEBOOK_API_SECRET = '9955be3b6e211b51921cb4b8eb08e69e'
LINKEDIN_CONSUMER_KEY = ''
LINKEDIN_CONSUMER_SECRET = ''
ORKUT_CONSUMER_KEY = ''
ORKUT_CONSUMER_SECRET = ''
GOOGLE_OAUTH2_CLIENT_KEY = ''
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 = 'complete'
LOGIN_ERROR_URL = '/login/error/'
#SOCIAL_AUTH_USER_MODEL = 'app.CustomUser'
SOCIAL_AUTH_ERROR_KEY = 'socialauth_error'
The rest of the codes are exactly the same in example in github.com/omab/django-social-auth
if you need any other code, just tell me.
Thanks a lot!
In my case the problem was that I had FACEBOOK_APP_SECRET instead of FACEBOOK_API_SECRET. It was due to the fact that I migrated from django-facebook to django-social-auth.
It may be you don't have the FACEBOOK_APP_ID or FACEBOOK_API_SECRET set.
Well, without seeing your configuration this will simply be a shot in the dark. But the django-social-auth code has this:
def complete_process(request, backend):
"""Authentication complete process"""
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
...
So, offhand, I would guess that you don't have the right backend configured or, at the very least, Django can't find it. Make sure you have the appropriate backend configured in AUTHENTICATION_BACKENDS and that you've obtained the required OAuth keys from the service you want to use.
Keep in mind, too, that this error occurs in the django-social-auth code in a few places, but always when the specified backend can't be retrieved.

Why is Django Caching my static with django.views.static.serve?

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.