def get_authenticated_user(self, redirect_uri, callback, scope=None, **args):
        """
        class RenrenHandler(tornado.web.RequestHandler, RenrenGraphMixin):
            @tornado.web.asynchronous
            @gen.engine
            def get(self):
                self.get_authenticated_user(
                    callback=(yield gen.Callback('key')),
                    redirect_uri=url)
                user = yield gen.Wait('key')
                if not user:
                    raise web.HTTPError(500, "Renren auth failed")
                # do something else
                self.finish()
        """

        code = self.get_argument('code', None)
        if not code:
            self.authorize_redirect(redirect_uri, scope=scope, **args)
            return
        self.get_access_token(
            code, callback=(yield gen.Callback('_RenrenGraphMixin.get_authenticated_user')),
            redirect_uri=redirect_uri)

        response = yield gen.Wait('_RenrenGraphMixin.get_authenticated_user')
        if not response:
            callback(None)
            return
        try:
            user = json_decode(response.body)
        except:
            logging.warning("Error response %s fetching %s",
                            response.body, response.request.url)
            callback(None)
            return
        if 'error' in user:
            logging.warning("Error response %s fetching %s",
                            user['error_description'], response.request.url)
            callback(None)
            return

        #{{{ get session key
        self.renren_request('renren_api/session_key', user['access_token'],
                            callback=(yield gen.Callback('_RenrenGraphMixin._session_key')))
        response = yield gen.Wait('_RenrenGraphMixin._session_key')
        if response.error and not response.body:
            logging.warning("Error response %s fetching %s",
                            response.error, response.request.url)
        elif response.error:
            logging.warning("Error response %s fetching %s: %s",
                            response.error, response.request.url, response.body)
        else:
            try:
                user['session'] = json_decode(response.body)
            except:
                pass
        #}}} #TODO delete when renren graph api released
        callback(user)
        return
def get_authenticated_user ( self , redirect_uri , callback , scope = None , ** args ) : code = self . get_argument ( 'code' , None ) if not code : self . authorize_redirect ( redirect_uri , scope = scope , ** args ) return self . get_access_token ( code , callback = ( yield gen . Callback ( '_RenrenGraphMixin.get_authenticated_user' ) ) , redirect_uri = redirect_uri ) response = yield gen . Wait ( '_RenrenGraphMixin.get_authenticated_user' ) if not response : callback ( None ) return try : user = json_decode ( response . body ) except : logging . warning ( "Error response %s fetching %s" , response . body , response . request . url ) callback ( None ) return if 'error' in user : logging . warning ( "Error response %s fetching %s" , user [ 'error_description' ] , response . request . url ) callback ( None ) return self . renren_request ( 'renren_api/session_key' , user [ 'access_token' ] , callback = ( yield gen . Callback ( '_RenrenGraphMixin._session_key' ) ) ) response = yield gen . Wait ( '_RenrenGraphMixin._session_key' ) if response . error and not response . body : logging . warning ( "Error response %s fetching %s" , response . error , response . request . url ) elif response . error : logging . warning ( "Error response %s fetching %s: %s" , response . error , response . request . url , response . body ) else : try : user [ 'session' ] = json_decode ( response . body ) except : pass callback ( user ) return
class RenrenHandler(tornado.web.RequestHandler, RenrenGraphMixin):
            @tornado.web.asynchronous
            @gen.engine
            def get(self):
                self.get_authenticated_user(
                    callback=(yield gen.Callback('key')),
                    redirect_uri=url)
                user = yield gen.Wait('key')
                if not user:
                    raise web.HTTPError(500, "Renren auth failed")
                # do something else
                self.finish()