是否可以在第 3 方网站的 iframe 中使用 FB Connect?
我在第 3 方网站上有一个 iframe。 iframe 内部是我的应用程序,用户使用 FB Connect 对其进行身份验证。我在 Ruby on Rails 网站上使用omniauth gem 来处理与 Facebook 的连接。
如果 a) 您已经登录 FB,并且 b) 您已经授予我的网站使用您的详细信息的权限,则它可以无缝运行。
如果其中任何一个缺失——在 FB 连接呼叫 Facebook 的那一刻——一切都会停止,我会得到 FB 徽标和一个点击进入 Facebook 的链接。当我点击该链接时 - 它会将我带出 iframe 并进入 Facebook。显然,一旦我返回,就没有 iframe 可供返回,而且我不再在第 3 方网站上,而是在我的网站上。
这种技术应该可行吗?如果是这样 - 我可能哪里出错了?正如我所说 - 如果满足 a) 和 b) - 它可以无缝运行。
I have an iframe on a 3rd party site. Inside the iframe is my application, which users authenticate to using FB Connect. I am using the omniauth gem with my Ruby on Rails site to handle the connection to Facebook.
It works seamlessly if a) you are already logged in to FB, and b) you have already given my site permission to use your details.
If either of these are missing - at that moment where FB connect calls out to Facebook - it all stops, and I get the FB logo and a link to click through to Facebook. When I click the link - it takes me out of my iframe and into Facebook. Obviously once I return - there is no iframe to go back to and I am no longer on the 3rd party site - but on mine.
Should this technique be possible? And if so - where might I be going wrong? As I said - if a) and b) are met - it works seamlessly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法从 iframe 内重定向到 Facebook,它必须加载到顶级页面中。这就是为什么你会看到 FB 徽标和链接,它的存在是为了强制突破 iframe 结构。如果您想避免这个中间步骤,请确保您自己执行顶级重定向(通常通过输出一些设置 top.location 的 javascript 代码)。
在返回端,您可以将redirect_uri设置为指向第3方网站,而不是直接指向您的网站(或接受默认的redirect_uri,这可能会无形中执行此操作),或者如果由于Facebook上的应用程序配置而无法做到这一点,检测您的页面正在加载到顶层,并重定向到第 3 方站点以强制其返回 iframe。
You can't do the redirect to Facebook from within an iframe, it has to be loaded into the top-level page. That's why you see the FB logo and link, it's there to force a breakout of the iframe structure. If you want to avoid that intermediate step, make sure you do a top-level redirect yourself (usually by outputting some javascript code that sets top.location).
On the return side, you can either set redirect_uri to point to the 3rd-party site instead of directly to your site (or accepting the default redirect_uri which is probably doing that invisibly), or if that is impossible because of your app config on Facebook, detect that your page is being loaded into the top level and do a redirect to the 3rd-party site to force it back into the iframe.