Facebook的登录的OAuth iframe的画布应用程序显示一个标志图像,并在进入Facebook.com的标题,而不是记录 [英] Facebook OAuth login for iframe canvas apps displays a logo image and a Go to Facebook.com caption instead of logging in

查看:166
本文介绍了Facebook的登录的OAuth iframe的画布应用程序显示一个标志图像,并在进入Facebook.com的标题,而不是记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立我的(IFRAME)的Facebook应用程序使用OAuth进行身份验证。
我用从Facebook的蟒蛇-SDK 的,但我没有真正的结果感到满意,但

问题是,当我重​​定向从来没有访问我的应用程序到登录页面,用户,我的iframe diplays一个丑陋的中间页,如下列之一:

如果用户点击转到Facebook.com的链接,她便重定向到标准的请求权限页面。

有没有办法避免的第一页,直接导致用户对第二个?

此问题发生在用户第一次访问未取得任何许可,我的应用程序呢。

登录code是基于Python的SDK中的OAuth的例子:

类LoginHandler(BaseHandler):
    DEF得到(个体经营):
        verification_ code = self.request.get(code)
        ARGS =字典(CLIENT_ID = FACEBOOK_APP_ID,REDIRECT_URI = self.request.path_url)
        如果self.request.get(code):
            ARGS [client_secret] = FACEBOOK_APP_SECRET
            ARGS [code] = self.request.get(code)
            raw_response =了urllib.urlopen(
                https://graph.facebook.com/oauth/access_token? +
                urllib.urlen code(参数))。阅读()
            logging.debug(生的access_token响应+ raw_response)
            响应= cgi.parse_qs(raw_response)
            的access_token =响应[的access_token] [ - 1]            #下载用户配置文件和缓存的本地实例
            #基本的个人资料信息
            图= facebook.GraphAPI(的access_token)
            简介= graph.get_object(我)            用户= User.get_by_key_name(配置文件[ID])
            如果没有用户:
                用户=用户(KEY_NAME = STR(配置文件[ID])
                                ID = STR(配置文件[ID])
                                名称=个人资料[名称],
                                名字=个人资料[如first_name],
                                PROFILE_URL =个人资料[链接]
                                的access_token =的access_token)
                user.put()
            ELIF user.access_token = ACCESS_TOKEN!
                #我们已经知道这个用户,但我们需要更新
                user.access_token =的access_token
                user.put()            set_cookie(self.response的fb_user,STR(配置文件[ID])
                       到期=选定了time.time()+ 30 * 86400)            self.response.headers [P3P] ='CP =IDC库拉ADMA我们的IND PHY ONL STA COM'
            self.redirect(/)
        其他:
            self.redirect(
                https://graph.facebook.com/oauth/authorize~~V? +
                urllib.urlen code(参数))


解决方案

çFacebook的使用出局内部框架的问题造成了对$ C $。的错误已经被提交在Facebook上的Bugzilla: HTTP://bugs.developers.facebook。净/ show_bug.cgi?ID = 11326

目前已知的唯一解决这个问题是从客户端做的第一重定向到 https://graph.facebook.com/oauth/authorize?(即通过JavaScript),使用

<脚本类型=文/ JavaScript的'>
 top.location.href =HTTPS://graph.facebook.com/oauth/authorize .......
 < / SCRIPT>

这可以在用户点击某个元素(例如,登录按钮)或每当访问特定页面(只是将其包含在HTML头)。

在被触发

I'm trying to set up my (iframe) Facebook application to use OAuth for authentication. I used the python-sdk from Facebook, but I'm not really satisfied by the result, yet.

The problem is that when I redirect a user that never accessed my application to the login page, my iframe diplays an ugly intermediate page, such as the following one:

If the user clicks on "Go to Facebook.com" link, she is then redirected to the standard "Request for Permission" page.

Is there any way to avoid the first page and lead the user straight to the second one?

This problem happens on the first access for users that haven't granted any permission to my application yet.

The login code is based on the OAuth example in the Python SDK:

class LoginHandler(BaseHandler):
    def get(self):
        verification_code = self.request.get("code")
        args = dict(client_id=FACEBOOK_APP_ID, redirect_uri=self.request.path_url)
        if self.request.get("code"):
            args["client_secret"] = FACEBOOK_APP_SECRET
            args["code"] = self.request.get("code")
            raw_response = urllib.urlopen(
                "https://graph.facebook.com/oauth/access_token?" +
                urllib.urlencode(args)).read()
            logging.debug("access_token raw response " + raw_response)
            response = cgi.parse_qs(raw_response)
            access_token = response["access_token"][-1]

            # Download the user profile and cache a local instance of the
            # basic profile info
            graph = facebook.GraphAPI(access_token)
            profile = graph.get_object("me")

            user = User.get_by_key_name(profile["id"])
            if not user:
                user = User(key_name=str(profile["id"]),
                                id=str(profile["id"]),
                                name=profile["name"],
                                firstname=profile["first_name"],
                                profile_url=profile["link"],
                                access_token=access_token)
                user.put()
            elif user.access_token != access_token:
                # we already know this user, but we need to update
                user.access_token = access_token
                user.put()

            set_cookie(self.response, "fb_user", str(profile["id"]),
                       expires=time.time() + 30 * 86400)

            self.response.headers["P3P"] = 'CP="IDC CURa ADMa OUR IND PHY ONL COM STA"'
            self.redirect("/")
        else:
            self.redirect(
                "https://graph.facebook.com/oauth/authorize?" +
                urllib.urlencode(args))

解决方案

The issue is caused to the code Facebook uses to bust out of iframes. A bug has been filed on Facebook's bugzilla: http://bugs.developers.facebook.net/show_bug.cgi?id=11326

The only known solution to this problem is to do the first redirect to https://graph.facebook.com/oauth/authorize? from the client side (i.e. Via JavaScript), using

 <script type='text/javascript'>
 top.location.href="https://graph.facebook.com/oauth/authorize?.......
 </script>

This can be triggered when the user clicks on some element (e.g. a login button) or whenever a specific page is visited (just include it in the HTML head).

这篇关于Facebook的登录的OAuth iframe的画布应用程序显示一个标志图像,并在进入Facebook.com的标题,而不是记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆