

def callback(self, request):
    'Process the douban redirect'
    code = request.GET.get('code')
    if (not code):
        reason = request.GET.get('error', 'No reason provided.')
        return AuthenticationDenied(reason, provider_name=self.name, provider_type=self.type)
    r = requests.post('https://www.douban.com/service/auth2/token', dict(client_id=self.consumer_key, client_secret=self.consumer_secret, grant_type='authorization_code', redirect_uri=request.route_url(self.callback_route), code=code))
    if (self.status_code != 200):
        raise ThirdPartyFailure(('Status %s: %s' % (r.status_code, r.content)))
    token_data = r.json()
    access_token = token_data['access_token']
    refresh_token = token_data.get('refresh_token')
    user_id = token_data['douban_user_id']
    profile = {
        'accounts': [{
            'domain': 'douban.com',
            'userid': user_id,
        }],
    }
    user_url = flat_url(('https://api.douban.com/v2/user/%s' % user_id))
    r = requests.get(user_url)
    if (r.status_code == 200):
        data = r.json()
        profile['displayName'] = data['name']
        profile['preferredUsername'] = data['name']
        profile['avatar'] = data['large_avatar']
        profile['data'] = data
    cred = {
        'oauthAccessToken': access_token,
        'oauthRefreshToken': refresh_token,
    }
    return DoubanAuthenticationComplete(profile=profile, credentials=cred, provider_name=self.name, provider_type=self.type)

dataset/ETHPy150Open bbangert/velruse/velruse/providers/douban.py DoubanProvider.callback/VarMisuse@110/162 `r`->`self`