Ejemplo n.º 1
0
    def do_auth(self, access_token, response=None, *args, **kwargs):
        response = response or {}

        data = self.user_data(access_token)

        if not isinstance(data, dict):
            # From time to time Facebook responds back a JSON with just
            # False as value, the reason is still unknown, but since the
            # data is needed (it contains the user ID used to identify the
            # account on further logins), this app cannot allow it to
            # continue with the auth process.
            raise AuthUnknownError(
                self, 'An error ocurred while retrieving '
                'users Facebook data')

        data['access_token'] = access_token
        if 'expires' in response:
            data['expires'] = response['expires']
        kwargs.update({'backend': self, 'response': data})
        return self.strategy.authenticate(*args, **kwargs)
Ejemplo n.º 2
0
 def auth_complete(self, *args, **kwargs):
     """Completes loging process, must return user instance"""
     self.process_error(self.data)
     try:
         response = self.request_access_token(
             self.ACCESS_TOKEN_URL,
             data=self.auth_complete_params(self.validate_state()),
             headers=self.auth_headers(),
             method=self.ACCESS_TOKEN_METHOD)
     except HTTPError as err:
         if err.response.status_code == 400:
             raise AuthCanceled(self)
         else:
             raise
     except KeyError:
         raise AuthUnknownError(self)
     self.process_error(response)
     return self.do_auth(response['access_token'],
                         response=response,
                         *args,
                         **kwargs)
Ejemplo n.º 3
0
 def process_error(self, data):
     if 'oauth_problem' in data:
         if data['oauth_problem'] == 'user_refused':
             raise AuthCanceled(self, 'User refused the access')
         raise AuthUnknownError(self, 'Error was ' + data['oauth_problem'])
Ejemplo n.º 4
0
class AuthUnknownErrorTest(BaseExceptionTestCase):
    exception = AuthUnknownError('foobar', 'some error')
    expected_message = 'An unknown error happened while ' \
                       'authenticating some error'