]> git.parisson.com Git - django-social-auth.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorStas Kravets <krvss@mail.ru>
Fri, 9 Mar 2012 09:01:31 +0000 (13:01 +0400)
committerStas Kravets <krvss@mail.ru>
Fri, 9 Mar 2012 09:01:31 +0000 (13:01 +0400)
Conflicts:
README.rst
doc/backends/google.rst
doc/configuration.rst
doc/miscellaneous.rst
example/app/pipeline.py
example/app/views.py
example/local_settings.py.template
example/settings.py
example/templates/home.html
social_auth/__init__.py
social_auth/backends/__init__.py
social_auth/backends/browserid.py
social_auth/backends/contrib/github.py
social_auth/backends/contrib/instagram.py
social_auth/backends/facebook.py
social_auth/backends/google.py
social_auth/backends/pipeline/misc.py
social_auth/backends/twitter.py
social_auth/tests/google.py
social_auth/utils.py
social_auth/views.py

1  2 
README.rst
doc/backends/google.rst
doc/configuration.rst
example/app/views.py
setup.py
social_auth/backends/__init__.py
social_auth/backends/facebook.py
social_auth/backends/google.py

diff --cc README.rst
index e7d1cfb61d96b3c273f223090940ade631c1508e,23eb502565a41bac25d78d3b0e0364bfadcd4889..2d167e100eea6e4c07ef72cff7f97b7adde48346
@@@ -894,9 -917,10 +920,9 @@@ Some particular use cases are listed be
  Miscellaneous
  -------------
  
- Join to django-social-auth_ community on Convore_ and bring any questions or
- suggestions that will improve this app.
+ Join to `django-social-auth discussion list`_ and bring any questions or suggestions
+ that would improve this application. Convore_ discussion group is deprecated since
+ the service is going to be shut down on April 1st.
 -
  If defining a custom user model, do not import social_auth from any models.py
  that would finally import from the models.py that defines your User class or it
  will make your project fail with a recursive import because social_auth uses
index c73cc7eb40b6b0dc59717df5835f9d8396233ed2,eef96766e2d106bce5b3b17226a102c47d2e39b9..65d3b1f48b57fd1f433a0b60fc040116a05b5ca8
@@@ -65,16 -73,20 +73,30 @@@ To enable OAuth2 support
  Check which applications can be included in their `Google Data Protocol Directory`_
  
  
+ Google OpenID 
+ -------------
+ Configurable settings:
+ - Supply a list of Google Apps account domain strings to be checked::
+     GOOGLE_WHITE_LISTED_DOMAINS = ['mygoogleappsdomain.com']
+ - Supply a list of Google Apps or Gmail email strings to be checked::
+     GOOGLE_WHITE_LISTED_EMAILS = ['me@mygoogleappsdomain.com', 'you@gmail.com']
 +Google OpenID 
 +-------------
 +
 +Configurable settings:
 +
 +- Supply a list of domain strings to be checked. The default (empty list) allows all domains.  If a list is provided and a user attempts to sign in with a Google account that is not in the list, then a ValueError will be raised and the user will be redirected to your login error page::
 +
 +    GOOGLE_WHITE_LISTED_DOMAINS = ['mydomain.com']
 +
 +
  Orkut
  -----
  
index 3b016201bcfc6fb6850ce0aef00fd1d8d6adae14,01e9204523d40d70b4249498d0feb69e7cb07613..0b44880ad1da7405c7469bf56fa8023db99ea572
@@@ -243,14 -229,54 +229,62 @@@ Configuratio
  
    Defaults to ``LOGIN_ERROR_URL``.
  
+ - The application catches any exception and logs errors to ``logger`` or
+   ``django.contrib.messagess`` application by default. But it's possible to
+   override the default behavior by defining a function to process the
+   exceptions using this setting::
+     SOCIAL_AUTH_PROCESS_EXCEPTIONS = 'social_auth.utils.process_exceptions'
+   The function parameters will ``request`` holding the current request object,
+   ``backend`` with the current backend and ``err`` which is the exception
+   instance.
+   Recently this set of exceptions were introduce to describe the situations
+   a bit more than the old ``ValueError`` usually raised::
+     AuthException           - Base exception class
+     AuthFailed              - Authentication failed for some reason
+     AuthCanceled            - Authentication was canceled by the user
+     AuthUnknownError        - An unknown error stoped the authentication
+                               process
+     AuthTokenError          - Unauthorized or access token error, it was
+                               invalid, impossible to authenticate or user
+                               removed permissions to it.
+     AuthMissingParameter    - A needed parameter to continue the process was
+                               missing, usually raised by the services that
+                               need some POST data like myOpenID
+   These are a subclass of ``ValueError`` to keep backward compatibility.
+   Having tracebacks is really useful when debugging, for that purpose this
+   setting was defined::
+     SOCIAL_AUTH_RAISE_EXCEPTIONS = DEBUG
+   It's default value is ``DEBUG``, so you need to set it to ``False`` to avoid
+   tracebacks when ``DEBUG = True``.
+ Some settings can be tweak by backend by adding the backend name prefix (all
+ uppercase and replace ``-`` with ``_``), here's the supported settings so far::
+         LOGIN_ERROR_URL
+         SOCIAL_AUTH_BACKEND_ERROR_URL
+         SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL
+         SOCIAL_AUTH_DISCONNECT_REDIRECT_URL
+         SOCIAL_AUTH_NEW_USER_REDIRECT_URL
+         SOCIAL_AUTH_LOGIN_REDIRECT_URL
+         SOCIAL_AUTH_INACTIVE_USER_URL
 +- The app catches any exception and logs errors to ``logger`` or
 +  ``django.contrib.messagess`` app. Having tracebacks is really useful when
 +  debugging, for that purpose this setting was defined::
 +
 +    SOCIAL_AUTH_RAISE_EXCEPTIONS = DEBUG
 +
 +  It's default value is ``DEBUG``, so you need to set it to ``False`` to avoid
 +  tracebacks when ``DEBUG = True``.
  
  .. _Model Manager: http://docs.djangoproject.com/en/dev/topics/db/managers/#managers
  .. _Login URL: http://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#login-url
Simple merge
diff --cc setup.py
Simple merge
Simple merge
index 92df6707e12d58fd275c175ad9985480e3ca81ba,9943e47057f1c4f154ded2ebcec5668b0fa7a028..b8dcaa9a3fe4e3d08fdbb9f4ccd4424c10680e1b
@@@ -13,11 -13,7 +13,11 @@@ field, check OAuthBackend class for det
  """
  import cgi
  from urllib import urlencode
- from urllib2 import urlopen
+ from urllib2 import urlopen, HTTPError
 +import base64
 +import hmac
 +import hashlib
 +import time
  
  from django.utils import simplejson
  from django.contrib.auth import authenticate
@@@ -79,46 -82,37 +86,55 @@@ class FacebookAuth(BaseOAuth2)
  
      def auth_complete(self, *args, **kwargs):
          """Completes loging process, must return user instance"""
 -        if 'code' not in self.data:
 -            if self.data.get('error') == 'access_denied':
 -                raise AuthCanceled(self)
 -            else:
 -                raise AuthException(self)
 +        access_token = None
 +        expires = None
 +
 +        if 'code' in self.data:
-             url = 'https://graph.facebook.com/oauth/access_token?' + \
-                   urlencode({'client_id': setting('FACEBOOK_APP_ID'),
-                              'redirect_uri': self.redirect_uri,
-                              'client_secret': setting('FACEBOOK_API_SECRET'),
-                              'code': self.data['code']})
-             response = cgi.parse_qs(urlopen(url).read())
++            url = ACCESS_TOKEN + urlencode({
++                'client_id': setting('FACEBOOK_APP_ID'),
++                'redirect_uri': self.redirect_uri,
++                'client_secret': setting('FACEBOOK_API_SECRET'),
++                'code': self.data['code']
++            })
++            try:
++                response = cgi.parse_qs(urlopen(url).read())
++            except HTTPError:
++                raise AuthFailed(self, 'There was an error authenticating the app')
++
 +            access_token = response['access_token'][0]
 +            if 'expires' in response:
 +                    expires = response['expires'][0]
  
 -        url = ACCESS_TOKEN + urlencode({
 -            'client_id': setting('FACEBOOK_APP_ID'),
 -            'redirect_uri': self.redirect_uri,
 -            'client_secret': setting('FACEBOOK_API_SECRET'),
 -            'code': self.data['code']
 -        })
 -        try:
 -            response = cgi.parse_qs(urlopen(url).read())
 -        except HTTPError:
 -            raise AuthFailed(self, 'There was an error authenticating the app')
 +        if 'signed_request' in self.data:
 +            response = load_signed_request(self.data.get('signed_request'))
  
 -        access_token = response['access_token'][0]
 -        data = self.user_data(access_token)
 +            if response is not None:
 +                access_token = response.get('access_token') or response.get('oauth_token') \
 +                               or self.data.get('access_token')
  
 -        if data is not None:
 -            data['access_token'] = access_token
 -            # expires will not be part of response if offline access
 -            # premission was requested
 -            if 'expires' in response:
 -                data['expires'] = response['expires'][0]
 +                if 'expires' in response:
 +                    expires = response['expires']
 +
 +        if access_token:
 +            data = self.user_data(access_token)
 -        kwargs.update({'auth': self,
 -                       'response': data,
 -                       self.AUTH_BACKEND.name: True})
 -        return authenticate(*args, **kwargs)
 +            if data is not None:
-                 if 'error' in data:
-                     error = self.data.get('error') or 'unknown error'
-                     raise ValueError('Authentication error: %s' % error)
 +                data['access_token'] = access_token
 +                # expires will not be part of response if offline access
-                 # premission was requested                
++                # premission was requested
 +                if expires:
-                     data['expires'] = expires
-             kwargs.update({'response': data, self.AUTH_BACKEND.name: True})
++                    data['expires'] = response['expires'][0]
++
++            kwargs.update({'auth': self,
++                           'response': data,
++                           self.AUTH_BACKEND.name: True})
++
 +            return authenticate(*args, **kwargs)
 +        else:
-             error = self.data.get('error') or 'unknown error'
-             raise ValueError('Authentication error: %s' % error)
++            if self.data.get('error') == 'access_denied':
++                raise AuthCanceled(self)
++            else:
++                raise AuthException(self)
  
      @classmethod
      def enabled(cls):
index 88896abc89f4a099bfda5e3466fe19c38ec42a73,c596c4903d3174ec652904ba8ca9fdc32d48e248..24e9083d034cf51a6b19569e5b43c724664fd71c
@@@ -80,11 -82,8 +82,11 @@@ class GoogleBackend(OpenIDBackend)
          is unique enought to flag a single user. Email comes from schema:
          http://axschema.org/contact/email
          """
-         # White listed domains (accepts all if list is empty)
-         domains = setting('GOOGLE_WHITE_LISTED_DOMAINS', [])
+         validate_whitelists(self, details['email'])
 +        if domains and details['email'].split('@', 1)[1] not in domains:
 +            raise ValueError('Domain not allowed')
 +
          return details['email']