(which is used for URLs matching) and Auth class, otherwise it won't be
enabled.
"""
-import logging
-logger = logging.getLogger(__name__)
-
from urllib2 import Request, urlopen
from urllib import urlencode
from urlparse import urlsplit
from django.utils import simplejson
from django.utils.importlib import import_module
-from social_auth.utils import setting
+from social_auth.utils import setting, log
from social_auth.store import DjangoOpenIDStore
from social_auth.backends.exceptions import StopPipeline
try:
mod = import_module(mod_name)
except ImportError:
- logger.exception('Error importing pipeline %s', name)
+ log('exception', 'Error importing pipeline %s', name)
else:
func = getattr(mod, func_name, None)
BACKENDS = {
'openid': OpenIdAuth
-}
\ No newline at end of file
+}
import urllib
-import logging
-logger = logging.getLogger(__name__)
from django.utils import simplejson
"""
import cgi
import urllib
-import logging
-logger = logging.getLogger(__name__)
-
from django.utils import simplejson
from django.contrib.auth import authenticate
No extra configurations are needed to make this work.
"""
-import logging
-logger = logging.getLogger(__name__)
-
from xml.etree import ElementTree
from xml.parsers.expat import ExpatError
username.livejournal.com. Username is retrieved from the identity url.
"""
import urlparse
-import logging
-logger = logging.getLogger(__name__)
from social_auth.backends import OpenIDBackend, OpenIdAuth, USERNAME
to enable this service support.
"""
import urllib
-import logging
-logger = logging.getLogger(__name__)
from django.utils import simplejson
By default account id and token expiration time are stored in extra_data
field, check OAuthBackend class for details on how to extend it.
"""
-import logging
-logger = logging.getLogger(__name__)
-
-
import cgi
from urllib import urlencode
from urllib2 import urlopen
from django.contrib.auth import authenticate
from social_auth.backends import BaseOAuth2, OAuthBackend, USERNAME
-from social_auth.utils import sanitize_log_data, setting
+from social_auth.utils import sanitize_log_data, setting, log
# Facebook configuration
try:
data = simplejson.load(urlopen(url))
- logger.debug('Found user data for token %s',
- sanitize_log_data(access_token),
- extra=dict(data=data))
except ValueError:
extra = {'access_token': sanitize_log_data(access_token)}
- logger.error('Could not load user data from Facebook.',
- exc_info=True, extra=extra)
+ log('error', 'Could not load user data from Facebook.',
+ exc_info=True, extra=extra)
+ else:
+ log('debug', 'Found user data for token %s',
+ sanitize_log_data(access_token),
+ extra=dict(data=data))
return data
def auth_complete(self, *args, **kwargs):
OpenID also works straightforward, it doesn't need further configurations.
"""
-import logging
-logger = logging.getLogger(__name__)
-
from urllib import urlencode
from urllib2 import Request, urlopen
By default account id is stored in extra_data field, check OAuthBackend
class for details on how to extend it.
"""
-import logging
-logger = logging.getLogger(__name__)
-
from django.utils import simplejson
from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME
No extra configurations are needed to make this work.
"""
-import logging
-logger = logging.getLogger(__name__)
-
from social_auth.backends import OpenIDBackend, OpenIdAuth
import urlparse
+import logging
from collections import defaultdict
from django.conf import settings
return getattr(settings, name, default)
+logger = None
+if not logger:
+ logging.basicConfig()
+ logger = logging.getLogger('SocialAuth')
+ logger.setLevel(logging.DEBUG)
+
+
+def log(level, *args, **kwargs):
+ """Small wrapper around logger functions."""
+ { 'debug': logger.debug,
+ 'error': logger.error,
+ 'exception': logger.exception,
+ 'warn': logger.warn }[level](*args, **kwargs)
+
+
if __name__ == '__main__':
import doctest
doctest.testmod()
on third party providers that (if using POST) won't be sending crfs
token back.
"""
-import logging
-logger = logging.getLogger(__name__)
-
from functools import wraps
from django.http import HttpResponseRedirect, HttpResponse, \
from django.views.decorators.csrf import csrf_exempt
from social_auth.backends import get_backend
-from social_auth.utils import sanitize_redirect, setting
+from social_auth.utils import sanitize_redirect, setting, log
DEFAULT_REDIRECT = setting('SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \
raise
backend_name = backend.AUTH_BACKEND.name
- logger.error(unicode(e), exc_info=True,
- extra=dict(request=request))
+ log('error', unicode(e), exc_info=True,
+ extra=dict(request=request))
if 'django.contrib.messages' in setting('INSTALLED_APPS'):
from django.contrib.messages.api import error
error(request, unicode(e), extra_tags=backend_name)
else:
- logger.warn('Messages framework not in place, some '+
+ 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)