From 6f16a07a0de530e889441e73c71aee254cf5e0fe Mon Sep 17 00:00:00 2001 From: YoruNoHikage Date: Wed, 27 Jan 2016 21:53:41 +0100 Subject: [PATCH] Add prefs to ease the process --- defaults/preferences/pref.js | 2 ++ modules/EchofonSign.jsm | 12 ++++++------ modules/TwitterClient.jsm | 13 +++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/defaults/preferences/pref.js b/defaults/preferences/pref.js index 923ec8a..9f8f6d0 100644 --- a/defaults/preferences/pref.js +++ b/defaults/preferences/pref.js @@ -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); diff --git a/modules/EchofonSign.jsm b/modules/EchofonSign.jsm index 4fa408c..4a0ba99 100644 --- a/modules/EchofonSign.jsm +++ b/modules/EchofonSign.jsm @@ -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); @@ -179,10 +183,6 @@ EchofonSign.OAuthSignature = function(str, secret) return OAuthSignatureByLibrary(str, secret); } } - - var signature = b64_hmac_sha1(consumerSecret + "&" + secret, str); - - return signature; } /* diff --git a/modules/TwitterClient.jsm b/modules/TwitterClient.jsm index 171d3ab..c9b1627 100644 --- a/modules/TwitterClient.jsm +++ b/modules/TwitterClient.jsm @@ -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); }; @@ -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(),