def auth_complete(self, oauth_token, oauth_verifier):
        """Return user, might be logged in"""
        name = self.AUTH_BACKEND_NAME + 'unauthorized_token_name'
        unauthed_token = self.request.session[name]
        del self.request.session[name]
        if not unauthed_token:
            raise ValueError('Missing unauthorized token')

        token = Token.from_string(unauthed_token)
        if token.key != oauth_token:
            raise ValueError('Incorrect tokens')

        access_token, user_data = self.access_token(token, oauth_verifier)
        return user_data
    def access_token(self, token, oauth_verifier):
        """Return request for access token value"""
        request = self.oauth_request(token, self.ACCESS_TOKEN_URL, oauth_verifier)
        response = self.fetch_response(request)
        params = parse_qs(response, keep_blank_values=False)
        
        user_data = dict()
        for key in 'user_id', 'screen_name':
            try:
                user_data[key] = params[key][0]
            except Exception:
                raise ValueError("'%s' not found in OAuth response." % key)

        return Token.from_string(response), user_data
    def auth_complete(self, oauth_token, oauth_verifier):
        """Return user, might be logged in"""
        name = self.AUTH_BACKEND_NAME + 'unauthorized_token_name'
        unauthed_token = self.request.session[name]
        del self.request.session[name]
        if not unauthed_token:
            raise ValueError('Missing unauthorized token')

        token = Token.from_string(unauthed_token)
        if token.key != oauth_token:
            raise ValueError('Incorrect tokens')

        access_token, user_data = self.access_token(token, oauth_verifier)
        return user_data
    def access_token(self, token, oauth_verifier):
        """Return request for access token value"""
        request = self.oauth_request(token, self.ACCESS_TOKEN_URL,
                                     oauth_verifier)
        response = self.fetch_response(request)
        params = parse_qs(response, keep_blank_values=False)

        user_data = dict()
        for key in 'user_id', 'screen_name':
            try:
                user_data[key] = params[key][0]
            except Exception:
                raise ValueError("'%s' not found in OAuth response." % key)

        return Token.from_string(response), user_data
 def unauthorized_token(self):
     """Return request for unauthorized token (first stage)"""
     request = self.oauth_request(token=None, url=self.REQUEST_TOKEN_URL)
     response = self.fetch_response(request)
     return Token.from_string(response)
 def unauthorized_token(self):
     """Return request for unauthorized token (first stage)"""
     request = self.oauth_request(token=None, url=self.REQUEST_TOKEN_URL)
     response = self.fetch_response(request)
     return Token.from_string(response)