'social_auth.backends',
'social_auth.backends.contrib',
'social_auth.backends.pipeline'],
+ package_data={'social_auth':['locale/*/LC_MESSAGES/*']},
long_description=long_description(),
install_requires=['oauth2>=1.5.167',
'python_openid>=2.2'],
from urllib2 import Request, urlopen
from urllib import urlencode
from urlparse import urlsplit
+from django.utils.translation import ugettext
from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE
from openid.consumer.discover import DiscoveryFailure
from django.utils import simplejson
from django.utils.importlib import import_module
-from social_auth.utils import setting, log, model_to_ctype, ctype_to_model
+from social_auth.utils import setting, log, model_to_ctype, ctype_to_model, DSAException
from social_auth.store import DjangoOpenIDStore
from social_auth.backends.exceptions import StopPipeline
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if self.data.get('error'):
- error = self.data.get('error_description') or self.data['error']
- raise ValueError('OAuth2 authentication failed: %s' % error)
+ if self.data['error'] == 'access_denied':
+ raise DSAException(ugettext(u'Authentication process was cancelled'))
+ error = self.data.get('error_description') or self.data.get('error')
+ raise DSAException(ugettext(u'Authentication failed: %s') % error)
client_id, client_secret = self.get_key_and_secret()
params = {'grant_type': 'authorization_code', # request auth code
raise ValueError('Unknown OAuth2 response type')
if response.get('error'):
+ if response.get('error') == 'access_denied':
+ raise DSAException(ugettext(u'Authentication process was cancelled'))
error = response.get('error_description') or response.get('error')
- raise ValueError('OAuth2 authentication failed: %s' % error)
+ raise DSAException(ugettext(u'Authentication failed: %s') % error)
else:
response.update(self.user_data(response['access_token']) or {})
kwargs.update({
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-02-16 21:41+0400\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%"
+"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
+
+#: build/lib/social_auth/views.py:70 social_auth/views.py:70
+msgid "Unknown authentication error. Try again later."
+msgstr "Непредвиденная ошибка аутентификации. Попробуйте позже."
+
+#: build/lib/social_auth/backends/__init__.py:634
+#: build/lib/social_auth/backends/__init__.py:655
+#: social_auth/backends/__init__.py:634 social_auth/backends/__init__.py:655
+msgid "Authentication process was cancelled"
+msgstr "Процесс аутентификации был прерван"
+
+#: build/lib/social_auth/backends/__init__.py:636
+#: build/lib/social_auth/backends/__init__.py:657
+#: social_auth/backends/__init__.py:636 social_auth/backends/__init__.py:657
+#, python-format
+msgid "Authentication failed: %s"
+msgstr "Ошибка аутентификации: %s"
+# coding=utf-8
import urlparse
import logging
from collections import defaultdict
from django.db.models import Model
from django.contrib.contenttypes.models import ContentType
+class DSAException(ValueError):
+ """
+ django-social-auth exception. This exception can be showed to user. It is thrown in normal situations – user declined
+ access, access token expired, etc.
+ """
+ pass
+
def sanitize_log_data(secret, data=None, leave_characters=4):
"""
from django.contrib.auth import login, REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.contrib import messages
+from django.utils.translation import ugettext
from django.views.decorators.csrf import csrf_exempt
from social_auth.backends import get_backend
-from social_auth.utils import sanitize_redirect, setting, log
+from social_auth.utils import sanitize_redirect, setting, log, DSAException
DEFAULT_REDIRECT = setting('SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \
try:
return func(request, backend, *args, **kwargs)
+ except DSAException, e:
+ backend_name = backend.AUTH_BACKEND.name
+ if 'django.contrib.messages' in setting('INSTALLED_APPS'):
+ from django.contrib.messages.api import error
+ error(request, unicode(e), extra_tags=backend_name)
+ else:
+ log('warn', 'Messages framework not in place, some '+
+ 'errors have not been shown to the user.')
+ url = setting('SOCIAL_AUTH_BACKEND_ERROR_URL', LOGIN_ERROR_URL)
+ return HttpResponseRedirect(url)
except Exception, e: # some error ocurred
if RAISE_EXCEPTIONS:
raise
if 'django.contrib.messages' in setting('INSTALLED_APPS'):
from django.contrib.messages.api import error
- error(request, unicode(e), extra_tags=backend_name)
+ error(request, ugettext(u'Unknown authentication error. Try again later.'), extra_tags=backend_name)
else:
log('warn', 'Messages framework not in place, some '+
'errors have not been shown to the user.')