在 Firefox 插件中验证 facebook 用户

发布于 2025-01-07 23:14:43 字数 189 浏览 4 评论 0原文

我正在尝试编写一个 Firefox 插件来访问 facebook 的数据。 现在我不确定如何获取访问令牌。 我尝试为桌面应用程序实现客户端流程(使用固定的重定向 uri),但我遇到的大问题是 JavaScript 不允许我等待重定向发生。 知道如何做到这一点吗?

据我了解,因为我没有网页,所以 JavaScript API 没有多大帮助,对吗?

I'm trying to write a Firefox plug-in that accesses data from facebook.
Now I'm not sure how to get an access token.
I tried to implement the client side flow for desktop apps (with the fixed redirect uri), but the big problem I encounter there, is that JavaScript doesn't allow me to wait for the redirect to happen.
Any idea how this could be done?

As far as I understood it, because I don't have a webpage, the JavaScript API doesn't help much, right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘然心甜 2025-01-14 23:14:43

我猜您正在浏览器选项卡中打开 https://www.facebook.com/dialog/oauth 让用户登录并授予您访问权限。您不需要在此处传递有效的重定向 URL,您可以使用肯定不起作用的内容,例如 http://my.extension.local/。然后您只需要检测选项卡何时重定向到该 URL。如果您有经典扩展,则可以在 < 上注册一个 进度监听器。该选项卡的 browser> 元素并查看 onLocationChange() 调用 - 一旦您看到以 http://my.extension.local/ 开头的位置,您就可以能取消请求并关闭选项卡,必要的数据位于 URL 中。如果您使用附加 SDK,您可以附加选项卡的 ready 事件侦听器,大致如下:

var tabs = require("tabs");
tabs.open({
  url: "https://www.facebook.com/dialog/oauth?...",
  inBackground: false,
  onReady: function(tab)
  {
    if (tab.url.indexOf("http://my.extension.local/") == 0)
    {
      ...
    }
  }
});

I guess that you are opening https://www.facebook.com/dialog/oauth in a browser tab to let the user log in and give you access. You don't need to pass a working redirect URL here, you can rather use something that will definitely not work, like http://my.extension.local/. Then you only need to detect when the tab gets redirected to that URL. If you have a classic extension, you register a progress listener on the <browser> element of that tab and look at onLocationChange() calls - once you see a location starting with http://my.extension.local/ you can cancel the request and close the tab, the necessary data is in the URL. If you use the Add-on SDK you can attach a ready event listener to the tab, something along these lines:

var tabs = require("tabs");
tabs.open({
  url: "https://www.facebook.com/dialog/oauth?...",
  inBackground: false,
  onReady: function(tab)
  {
    if (tab.url.indexOf("http://my.extension.local/") == 0)
    {
      ...
    }
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文