コード例 #1
0
    def auth_complete(self, *args, **kwargs):
        """Return user, might be logged in"""
        # Multiple unauthorized tokens are supported (see #521)
        name = self.AUTH_BACKEND.name + 'unauthorized_token_name'
        token = None
        unauthed_tokens = self.request.session.get(name) or []
        if not unauthed_tokens:
            raise AuthTokenError(self, 'Missing unauthorized token')
        for unauthed_token in unauthed_tokens:
            token = Token.from_string(unauthed_token)
            if token.key == self.data.get('oauth_token', 'no-token'):
                unauthed_tokens = list(
                    set(unauthed_tokens) - set([unauthed_token]))
                self.request.session[name] = unauthed_tokens
                self.request.session.modified = True
                break
        else:
            raise AuthTokenError(self, 'Incorrect tokens')

        try:
            access_token = self.access_token(token)
        except HTTPError, e:
            if e.code == 400:
                raise AuthCanceled(self)
            else:
                raise
コード例 #2
0
ファイル: __init__.py プロジェクト: liang0/sentry-1
    def auth_complete(self, *args, **kwargs):
        """Return user, might be logged in"""
        # Multiple unauthorized tokens are supported (see #521)
        name = self.AUTH_BACKEND.name + "unauthorized_token_name"
        token = None
        unauthed_tokens = self.request.session.get(name) or []
        if not unauthed_tokens:
            raise AuthTokenError(self, "Missing unauthorized token")
        for unauthed_token in unauthed_tokens:
            token = unauthed_token
            if not isinstance(unauthed_token, dict):
                token = parse_qs(unauthed_token)
            if token.get("oauth_token") == self.data.get("oauth_token"):
                unauthed_tokens = list(
                    set(unauthed_tokens) - set([unauthed_token]))
                self.request.session[name] = unauthed_tokens
                self.request.session.modified = True
                break
        else:
            raise AuthTokenError(self, "Incorrect tokens")

        try:
            access_token = self.access_token(token)
        except HTTPError as e:
            if e.code == 400:
                raise AuthCanceled(self)
            else:
                raise
        return self.do_auth(access_token, *args, **kwargs)
コード例 #3
0
    def user_data(self, access_token, *args, **kwargs):
        """Loads user data from service"""
        data = None
        params = backend_setting(self, self.EXTRA_PARAMS_VAR_NAME, {})
        params['access_token'] = access_token
        url = FACEBOOK_ME + urlencode(params)

        try:
            data = simplejson.load(dsa_urlopen(url))
        except ValueError:
            extra = {'access_token': sanitize_log_data(access_token)}
            log('error',
                'Could not load user data from Facebook.',
                exc_info=True,
                extra=extra)
        except HTTPError:
            extra = {'access_token': sanitize_log_data(access_token)}
            log('error',
                'Error validating access token.',
                exc_info=True,
                extra=extra)
            raise AuthTokenError(self)
        else:
            log('debug',
                'Found user data for token %s',
                sanitize_log_data(access_token),
                extra={'data': data})
        return data
コード例 #4
0
ファイル: reddit.py プロジェクト: xochilt/django-social-auth
 def user_data(self, access_token, *args, **kwargs):
     """Grab user profile information from reddit."""
     try:
         request = Request(
             'https://oauth.reddit.com/api/v1/me.json',
             headers={'Authorization': 'bearer %s' % access_token})
         return simplejson.load(dsa_urlopen(request))
     except ValueError:
         return None
     except HTTPError:
         raise AuthTokenError(self)
コード例 #5
0
 def user_data(self, access_token, *args, **kwargs):
     """Grab user profile information from Bratabase."""
     try:
         request = Request(
             self.ME_URL,
             headers={'Authorization': 'bearer %s' % access_token})
         return simplejson.load(dsa_urlopen(request))
     except ValueError:
         return None
     except HTTPError:
         raise AuthTokenError(self)
コード例 #6
0
ファイル: amazon.py プロジェクト: Memrise/django-social-auth
 def user_data(self, access_token, *args, **kwargs):
     """Grab user profile information from amazon."""
     url = 'https://www.amazon.com/ap/user/profile?access_token=%s' % \
                 access_token
     try:
         response = simplejson.load(dsa_urlopen(Request(url)))
     except ValueError:
         return None
     except HTTPError:
         raise AuthTokenError(self)
     else:
         if 'Profile' in response:
             response = {
                 'user_id': response['Profile']['CustomerId'],
                 'name': response['Profile']['Name'],
                 'email': response['Profile']['PrimaryEmail']
             }
         return response