Bug 1109178 - Make OAuth implementation work with Evernote. r=clokep, a=rkent
authorMike Kaply <mozilla@kaply.com>
Mon, 27 Apr 2015 21:17:54 -0400
changeset 25893 891622c58ed265078b6d2e3049d6d88112f73d4d
parent 25892 60e4523811563b5a875a83dead197ae459a9a95c
child 25894 67a24915fc34dad28051948188e688f63cfcdfab
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep, rkent
bugs1109178
Bug 1109178 - Make OAuth implementation work with Evernote. r=clokep, a=rkent
mail/base/modules/oauth.jsm
--- a/mail/base/modules/oauth.jsm
+++ b/mail/base/modules/oauth.jsm
@@ -13,33 +13,35 @@ const {classes: Cc, interfaces: Ci, resu
 var EXPORTED_SYMBOLS = ["OAuth"];
 
 Cu.import("resource://gre/modules/Http.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource:///modules/gloda/log4moz.js");
 
 function OAuth(aDisplayName, aBaseUri, aAuthUri, aAuthToken, aAuthTokenSecret,
-               aAppKey, aAppSecret, aSignatureMethod, aTempCredentialsMethod,
-               aAuthorizeMethod, aRequestCredentialsMethod)
+               aAppKey, aAppSecret, aSignatureMethod,
+               aTempCredentialsMethod = "oauth/request_token",
+               aAuthorizeMethod = "oauth/authorize",
+               aRequestCredentialsMethod = "oauth/access_token")
 {
   this._userInfo = {};
   this.displayName = aDisplayName;
   this.baseURI = aBaseUri;
   this.authURI = aAuthUri;
   this.token = aAuthToken;
   this.tokenSecret = aAuthTokenSecret;
   this.consumerKey = aAppKey;
   this.consumerSecret = aAppSecret;
   this.log = Log4Moz.getConfiguredLogger("TBOAuth");
 
   this.signatureMethod = aSignatureMethod || "HMAC-SHA1";
-  this.tempCredentialsMethod = aTempCredentialsMethod || "oauth/request_token";
-  this.authorizeMethod = aAuthorizeMethod || "oauth/authorize";
-  this.requestCredentialsMethod = aRequestCredentialsMethod || "oauth/access_token";
+  this.tempCredentialsMethod = aTempCredentialsMethod;
+  this.authorizeMethod = aAuthorizeMethod;
+  this.requestCredentialsMethod = aRequestCredentialsMethod;
 }
 
 OAuth.prototype = {
   consumerKey: "",
   consumerSecret: "",
   completionURI: "http://oauthcallback.local/",
   baseURI: "",
   token : "",
@@ -95,20 +97,22 @@ OAuth.prototype = {
     let nonce = "";
     for (let i = 0; i < kNonceLength; ++i)
       nonce += kChars[Math.floor(Math.random() * kChars.length)];
 
     let params = (aOAuthParams || []).concat([
       ["oauth_consumer_key", this.consumerKey],
       ["oauth_nonce", nonce],
       ["oauth_signature_method", this.signatureMethod],
-      ["oauth_token", this.token],
       ["oauth_timestamp", Math.floor(((new Date()).getTime()) / 1000)],
       ["oauth_version", "1.0"]
     ]);
+    if (this.token) {
+      params.push(["oauth_token", this.token]);
+    }
 
     let dataParams = [];
     let url = /^https?:/.test(aUrl) ? aUrl : this.baseURI + aUrl;
     let urlSpec = url;
     let queryIndex = url.indexOf("?");
     if (queryIndex != -1) {
       urlSpec = url.slice(0, queryIndex);
       dataParams = url.slice(queryIndex + 1).split("&")
@@ -186,17 +190,18 @@ OAuth.prototype = {
                      null, "POST", null,
                      this.onRequestTokenReceived,
                      this.connectFailureCallback, this,
                      oauthParams);
   },
   onRequestTokenReceived: function(aData) {
     this.log.info("Received request token.");
     let data = this._parseURLData(aData);
-    if (!data.oauth_token || !data.oauth_token_secret) {
+    if (!data.oauth_token ||
+        (this.signatureMethod == "HMAC-SHA1" && !data.oauth_token_secret)) {
       this.log.info("didn't get request token");
       this.connectFailureCallback();
       return;
     }
     this.token = data.oauth_token;
     this.tokenSecret = data.oauth_token_secret;
 
     this.requestAuthorization();
@@ -284,17 +289,17 @@ OAuth.prototype = {
                      aVerifier);
   },
   onAccessTokenReceived: function(aData) {
     this.log.info("Received access token. urlData = " + aData);
     let result = this._parseURLData(aData);
 
     this.token = result.oauth_token;
     this.tokenSecret = result.oauth_token_secret;
-    this.connectSuccessCallback();
+    this.connectSuccessCallback(result);
   },
 
 
   cleanUp: function() {
     this.finishAuthorizationRequest();
     if (this._pendingRequests.length != 0) {
       for each (let request in this._pendingRequests)
         request.abort();