Skip to content

Commit

Permalink
Add prefs to ease the process
Browse files Browse the repository at this point in the history
  • Loading branch information
YoruNoHikage committed Jan 28, 2016
1 parent 4443c8b commit 6f16a07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions defaults/preferences/pref.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pref("extensions.twitternotifier.clearDB", false);
pref("extensions.twitternotifier.debug", false);
pref("extensions.twitternotifier.sync", "{}");
pref("extensions.twitternotifier.accounts", "{}");
pref("extensions.twitternotifier.customKey", "");
pref("extensions.twitternotifier.customSecret", "");
pref("extensions.twitternotifier.checkFollow", 0);
pref("extensions.twitternotifier.applicationMode", "window");
pref("extensions.twitternotifier.splashScreen", true);
Expand Down
12 changes: 6 additions & 6 deletions modules/EchofonSign.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ EchofonSign.getSignatureForSyncServer = function(str)

EchofonSign.OAuthSignature = function(str, secret)
{
var consumerSecret = "%CONSUMER_SECRET%";
if(!consumerSecret) {
var prefs = Cc['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch("extensions.twitternotifier.");
try {
const customSecret = prefs.getCharPref("customSecret");
if(!customSecret) throw 'No custom key';
return b64_hmac_sha1(customSecret + "&" + secret, str);
} catch(e) {
if (Cc['@naan.net/twitterfox-sign;1']) {
var com = Cc['@naan.net/twitterfox-sign;1'].getService(Ci.nsITwitterFoxSign);
return com.OAuthSignature(str, secret);
Expand All @@ -179,10 +183,6 @@ EchofonSign.OAuthSignature = function(str, secret)
return OAuthSignatureByLibrary(str, secret);
}
}

var signature = b64_hmac_sha1(consumerSecret + "&" + secret, str);

return signature;
}

/*
Expand Down
13 changes: 11 additions & 2 deletions modules/TwitterClient.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ const {classes:Cc, interfaces:Ci, utils:Cu} = Components;

Cu.import("resource://echofon/EchofonHttpRequest.jsm");

const OAUTH_CONSUMER_KEY = "%CONSUMER_KEY%" || "yqoymTNrS9ZDGsBnlFhIuw";
const TWITTER_API_URL = "api.twitter.com/1.1/";

function getOAuthConsumerKey() {
var prefs = Cc['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch("extensions.twitternotifier.");
const defaultKey = "yqoymTNrS9ZDGsBnlFhIuw";
try {
return prefs.getCharPref("customKey") || defaultKey;
} catch(e) {
return defaultKey;
}
}

function convertToHexString(data)
{
var toHexString = function(charCode) { return ("0" + charCode.toString(16)).slice(-2); };
Expand Down Expand Up @@ -102,7 +111,7 @@ TwitterClient.buildOAuthHeader = function (user, method, url, param)

var s = convertToHexString(hash);

var oauthparam = {"oauth_consumer_key" : OAUTH_CONSUMER_KEY,
var oauthparam = {"oauth_consumer_key" : getOAuthConsumerKey(),
"oauth_timestamp" : ts,
"oauth_signature_method" : "HMAC-SHA1",
"oauth_nonce" : s + Math.random(),
Expand Down

0 comments on commit 6f16a07

Please sign in to comment.