def callback(self, request):
        """Process the Twitter redirect"""
        if 'denied' in request.GET:
            return AuthenticationDenied("User denied authentication",
                                        provider_name=self.name,
                                        provider_type=self.type)
        verifier = request.GET.get('oauth_verifier')
        if not verifier:
            raise ThirdPartyFailure("No oauth_verifier returned")

        request_token = request.session.pop('velruse.token')

        # turn our request token into an access token
        oauth = OAuth1(
            self.consumer_key,
            client_secret=self.consumer_secret,
            resource_owner_key=request_token['oauth_token'],
            resource_owner_secret=request_token['oauth_token_secret'],
            verifier=verifier)
        resp = requests.post(ACCESS_URL, auth=oauth)
        if resp.status_code != 200:
            raise ThirdPartyFailure("Status %s: %s" % (
                resp.status_code, resp.content))
        access_token = dict(parse_qsl(resp.text))
        creds = {
            'oauthAccessToken': access_token['oauth_token'],
            'oauthAccessTokenSecret': access_token['oauth_token_secret'],
        }

        username = access_token['screen_name']

        # Setup the normalized contact info
        profile = {}
        profile['accounts'] = [{
            'domain': 'twitter.com',
            'userid': access_token['user_id'],
            'username': username,
        }]
        profile['displayName'] = username
        profile['preferredUsername'] = username

        oauth = OAuth1(
            self.consumer_key,
            client_secret=self.consumer_secret,
            resource_owner_key=access_token['oauth_token'],
            resource_owner_secret=access_token['oauth_token_secret'])
        resp = requests.get(DATA_URL % username, auth=oauth)
        if resp.status_code == 200:
            data = resp.json()
            if 'name' in data:
                # replace display name with the full name
                profile['displayName'] = data['name']
                profile['name'] = {'formatted': profile['displayName']}
            if 'url' in data:
                profile['urls'] = [{'value': data['url']}]
            if 'location' in data:
                profile['addresses'] = [{'formatted': data['location']}]
            if 'profile_image_url' in data:
                profile['photos'] = [{'value': data['profile_image_url']}]
            if data.get('utc_offset'):
                offset = float(data['utc_offset']) / 3600
                h = int(offset)
                m = int(abs(offset - h) * 60)
                profile['utcOffset'] = '{h:+03d}:{m:02d}'.format(h=h, m=m)

        return TwitterAuthenticationComplete(profile=profile,
                                             credentials=creds,
                                             provider_name=self.name,
                                             provider_type=self.type)
dataset/ETHPy150Open bbangert/velruse/velruse/providers/twitter.py/TwitterProvider.callback/original