Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[backends] Added better error handling when parsing the <backend>_EXT…

…RA_DATA setting
  • Loading branch information...
commit 039ca737385f569221b06d3da91d54f10c8f0aa8 1 parent 4875ab1
Emil Stenqvist emilisto authored
Showing with 27 additions and 17 deletions.
  1. +23 −16 social_auth/backends/__init__.py
  2. +4 −1 social_auth/exceptions.py
39 social_auth/backends/__init__.py
View
@@ -39,7 +39,7 @@
AuthCanceled, AuthUnknownError, \
AuthTokenError, AuthMissingParameter, \
AuthStateMissing, AuthStateForbidden, \
- NotAllowedToDisconnect
+ NotAllowedToDisconnect, BackendError
from social_auth.backends.utils import build_consumer_oauth_request
@@ -225,23 +225,30 @@ def extra_data(cls, user, uid, response, details=None):
data = {'access_token': response.get('access_token', '')}
name = cls.name.replace('-', '_').upper()
names = (cls.EXTRA_DATA or []) + setting(name + '_EXTRA_DATA', [])
+
for entry in names:
- if len(entry) == 2:
- (name, alias), discard = entry, False
- elif len(entry) == 3:
- name, alias, discard = entry
- elif len(entry) == 1:
- name = alias = entry
- discard = False
- else: # ???
- continue
-
- value = response.get(name)
- if discard and not value:
- continue
- data[alias] = value
- return data
+ if type(entry) is str:
+ entry = (entry,)
+ try:
+ if len(entry) == 3:
+ name, alias, discard = entry
+ elif len(entry) == 2:
+ (name, alias), discard = entry, False
+ elif len(entry) == 1:
+ (name,), (alias,), discard = entry, entry, False
+ else:
+ raise ValueError('invalid tuple for EXTRA_DATA entry' % entry)
+
+ value = response.get(name)
+ if discard and not value:
+ continue
+ data[alias] = value
+
+ except (TypeError, ValueError), e:
+ raise BackendError('invalid entry: %s' % (entry,))
+
+ return data
class OpenIDBackend(SocialAuthBackend):
"""Generic OpenID authentication backend"""
5 social_auth/exceptions.py
View
@@ -5,8 +5,11 @@ class SocialAuthBaseException(ValueError):
"""Base class for pipeline exceptions."""
pass
+class BackendError(SocialAuthBaseException):
+ def __unicode__(self):
+ return ugettext(u'Backend error: %s' % self.message)
-class WrongBackend(SocialAuthBaseException):
+class WrongBackend(BackendError):
def __init__(self, backend_name):
self.backend_name = backend_name
Please sign in to comment.
Something went wrong with that request. Please try again.