繁体   English   中英

如何在Firefox插件中使用oauthorizer

[英]How to use oauthorizer in Firefox addon

我正在尝试在Firefox中使用oauth2 ,我从Google找到了以下模块:

https://github.com/mozilla/oauthorizer

但是,我不确定如何使用它。

我根据该项目的README尝试了以下方法,

Components.utils.import("resource://oauthorizer/modules/oauthconsumer.js");

但是它报告以下错误:

“`Components`在这种情况下不可用。Components提供的功能可能在SDK模块中可用: https : //developer.mozilla.org/en-US/Add-ons/SDK但是,如果仍然需要导入Components ,您可以使用chrome模块的属性作为Component属性的快捷方式:快捷方式:Cc = Components.classes Ci = Components.interfaces Cu = Components.utils CC = Components.Constructor示例:let {Cc,Ci} = require('铬');”

然后,我尝试了这个:

let {Cu} = require("chrome");
Cu.import("resource://oauthorizer/modules/oauthconsumer.js");

但是我得到了这个错误:

“组件返回的失败代码:0x80040111(NS_ERROR_NOT_AVAILABLE)[nsIXPCComponents_Utils.import]”

可能需要在package.json中设置一些内容吗? 还是有一些导入外部模块的特殊机制?

任何帮助深表感谢!

最后,这是我所做的:(请注意,我在附件开发中使用了jpm

  1. 使用npm安装oauthorizer。 在插件的根文件夹中,运行以下命令:

npm install oauthorizer --save

  1. 在插件脚本( index.js )中,添加以下内容:
var OAuthConsumer = require("oauthorizer/lib/oauthconsumer.js").OAuthConsumer;
  1. 稍微修改oauthconsumer.js以更新路径:

例如,将require("sha1")替换为require("./sha1")

我很确定这不是最好的解决方案,但至少可以奏效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM