[英]How to use oauthorizer in Firefox addon
I am trying to use oauth2
in Firefox, and I found this module from Google: 我正在尝试在Firefox中使用
oauth2
,我从Google找到了以下模块:
https://github.com/mozilla/oauthorizer https://github.com/mozilla/oauthorizer
However, I am not sure how to use it. 但是,我不确定如何使用它。
I tried the following according to README
of the project, 我根据该项目的
README
尝试了以下方法,
Components.utils.import("resource://oauthorizer/modules/oauthconsumer.js");
Yet it reports error of following: 但是它报告以下错误:
"`Components` is not available in this context.Functionality provided by Components may be available in an SDKmodule: https://developer.mozilla.org/en-US/Add-ons/SDK However, if you still need to import Components, you may use the`chrome` module's properties for shortcuts to Component properties:Shortcuts: Cc = Components.classes Ci = Components.interfaces Cu = Components.utils CC = Components.Constructor Example: let { Cc, Ci } = require('chrome');"
“`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('铬');”
Then, I tried this: 然后,我尝试了这个:
let {Cu} = require("chrome");
Cu.import("resource://oauthorizer/modules/oauthconsumer.js");
But I got this error then: 但是我得到了这个错误:
"Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXPCComponents_Utils.import]"
“组件返回的失败代码:0x80040111(NS_ERROR_NOT_AVAILABLE)[nsIXPCComponents_Utils.import]”
May be I need to set up something in the package.json? 可能需要在package.json中设置一些内容吗? Or there are some special mechanisms to import the external modules?
还是有一些导入外部模块的特殊机制?
Any help is much appreciated! 任何帮助深表感谢!
Finally, this is what I did: (Please note that I used jpm for the addon development) 最后,这是我所做的:(请注意,我在附件开发中使用了jpm )
npm
. npm
安装oauthorizer。 Inside the root folder of addon, run the following: npm install oauthorizer --save
index.js
), add the following: index.js
)中,添加以下内容: var OAuthConsumer = require("oauthorizer/lib/oauthconsumer.js").OAuthConsumer;
oauthconsumer.js
a little bit to update the path: oauthconsumer.js
以更新路径: eg replace require("sha1")
to require("./sha1")
例如,将
require("sha1")
替换为require("./sha1")
I am pretty sure it's not the best solution, but at least it works. 我很确定这不是最好的解决方案,但至少可以奏效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.