I am trying to use oauth2
in Firefox, and I found this module from Google:
https://github.com/mozilla/oauthorizer
However, I am not sure how to use it.
I tried the following according to README
of the project,
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');"
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]"
May be I need to set up something in the 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)
npm
. Inside the root folder of addon, run the following:npm install oauthorizer --save
index.js
), add the following:var OAuthConsumer = require("oauthorizer/lib/oauthconsumer.js").OAuthConsumer;
oauthconsumer.js
a little bit to update the path:e.g. replace require("sha1")
to require("./sha1")
I am pretty sure it's not the best solution, but at least it works.
User contributions licensed under CC BY-SA 3.0