[Pkg-mozext-commits] [gcontactsync] 09/19: Issue #68: OAuth2 doesn't work when a server is running. Reverted the previous change and instead switched to the urn redirect_uri which changes the title instead of redirecting

David Prévot taffit at moszumanska.debian.org
Thu Apr 2 17:47:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository gcontactsync.

commit f8ef96a0a789e629bc2c4d57f7ed5fcafbf8399b
Author: Josh Geenen <joshgeenen at gmail.com>
Date:   Tue Mar 31 19:40:26 2015 -0500

    Issue #68: OAuth2 doesn't work when a server is running.  Reverted the previous change and instead switched to the urn redirect_uri which changes the title instead of redirecting
---
 src/content/AccountSetupWizard.js        |  6 ++++-
 src/content/GHttpRequest.js              |  3 +--
 src/content/OAuth2.js                    | 42 +++++++++++---------------------
 src/content/Preferences.js               |  3 +--
 src/content/gdata.js                     |  4 +--
 src/defaults/preferences/gContactSync.js |  2 --
 src/locale/en-US/options.dtd             |  2 --
 7 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/src/content/AccountSetupWizard.js b/src/content/AccountSetupWizard.js
index 02f0388..8cd867c 100644
--- a/src/content/AccountSetupWizard.js
+++ b/src/content/AccountSetupWizard.js
@@ -136,7 +136,11 @@ com.gContactSync.AccountSetupWizard = {
     browser.loadURI(url);
 
     if (!this.mWizardLoaded) {
-      com.gContactSync.OAuth2.init(browser, com.gContactSync.gdata.REDIRECT_URI, this.onSuccessfulAuthentication);
+
+      com.gContactSync.OAuth2.init(browser,
+                                   com.gContactSync.gdata.REDIRECT_URI,
+                                   this.onSuccessfulAuthentication,
+                                   com.gContactSync.gdata.REDIRECT_TITLE);
       this.mWizardLoaded = true;
     }
   },
diff --git a/src/content/GHttpRequest.js b/src/content/GHttpRequest.js
index 3cc0e87..43b8884 100644
--- a/src/content/GHttpRequest.js
+++ b/src/content/GHttpRequest.js
@@ -82,8 +82,7 @@ com.gContactSync.GHttpRequest = function gCS_GHttpRequest(aType, aAuth, aUrl, aB
     this.addParameter("code", aAuth);
     this.addParameter("client_id", com.gContactSync.gdata.CLIENT_ID);
     this.addParameter("client_secret", com.gContactSync.gdata.CLIENT_SECRET);
-    this.addParameter("redirect_uri", com.gContactSync.gdata.REDIRECT_URI +
-                      ":" + com.gContactSync.Preferences.mSyncPrefs.authenticationPort.value);
+    this.addParameter("redirect_uri", com.gContactSync.gdata.REDIRECT_URI);
     this.addParameter("grant_type", com.gContactSync.gdata.TOKEN_REQUEST_GRANT_TYPE);
     break;
   case "REFRESH_REQUEST":
diff --git a/src/content/OAuth2.js b/src/content/OAuth2.js
index 53bb2ae..dd1bd90 100644
--- a/src/content/OAuth2.js
+++ b/src/content/OAuth2.js
@@ -15,7 +15,7 @@
  *
  * The Initial Developer of the Original Code is
  * Josh Geenen <gcontactsync at pirules.org>.
- * Portions created by the Initial Developer are Copyright (C) 2014
+ * Portions created by the Initial Developer are Copyright (C) 2014-2015
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
@@ -53,11 +53,12 @@ com.gContactSync.OAuth2 = {
    * @param aRedirectURI {string} The redirect URI to watch for.
    * @param aCallback {function} The function to call when the browser's source changes to the redirect URI.
    */
-  init: function OAuth2_init(aBrowserElem, aRedirectURI, aCallback) {
+  init: function OAuth2_init(aBrowserElem, aRedirectURI, aCallback, aBrowserTitle) {
     this.mBrowserElem = aBrowserElem;
     this.mRedirectURI = aRedirectURI;
     this.mCallback = aCallback;
-    this.mBrowserElem.addProgressListener(this.mListener);
+    this.mBrowserTitle = aBrowserTitle;
+    setTimeout(this.checkTitle, 1000);
   },
   /**
    * Notify that an authorization code was received.  Sends a token request using the code.
@@ -66,7 +67,6 @@ com.gContactSync.OAuth2 = {
    */
   onCodeReceived: function OAuth2_onCodeReceived(aCode) {
     com.gContactSync.LOGGER.LOG("Received an authorization code: " + aCode);
-    this.mBrowserElem.removeProgressListener(com.gContactSync.OAuth2.mListener);
     this.mBrowserElem.loadURI("");
     var request = new com.gContactSync.GHttpRequest("TOKEN_REQUEST", aCode);
     request.mOnSuccess = com.gContactSync.OAuth2.onTokenReceived;
@@ -85,30 +85,16 @@ com.gContactSync.OAuth2 = {
     com.gContactSync.OAuth2.mCallback(JSON.parse(aHttpReq.responseText));
   },
   /**
-   * A nsIWebProgressListener that listens for a location change to the redirect URI.
-   * Notifies OAuth2.
+   * Checks the title of the browser for the requested title indicating a code.
    */
-  mListener: {
-    /** Implements nsIWebProgressListener, nsISupportsWeakRefrence */
-    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIWebProgressListener,
-                                           Components.interfaces.nsISupportsWeakReference]),
-    /**
-     * Watches for a location change to the redirect URI.
-     *
-     * @param aWebProgress The progress.
-     * @param aRequest The request.
-     * @param aLocation The location.
-     */
-    onLocationChange: function (aWebProgress, aRequest, aLocation) {
-      com.gContactSync.LOGGER.LOG("Observed a location change: " + aLocation.spec);
-      if (aLocation.spec.indexOf(com.gContactSync.OAuth2.mRedirectURI) === 0) {
-        var code = com.gContactSync.parseURLParameters(aLocation.spec).code;
-        com.gContactSync.OAuth2.onCodeReceived(code);
-      }
-    },
-    onStateChange: function () {},
-    onProgressChange: function () {},
-    onStatusChange: function () {},
-    onSecurityChange: function () {},
+  checkTitle: function OAuth2_checkTitle() {
+
+    var title = com.gContactSync.OAuth2.mBrowserElem.contentDocument.title;
+
+    if (title.indexOf(com.gContactSync.OAuth2.mBrowserTitle) === 0) {
+      com.gContactSync.OAuth2.onCodeReceived(title.substring(com.gContactSync.OAuth2.mBrowserTitle.length));
+    } else {
+      setTimeout(com.gContactSync.OAuth2.checkTitle, 500);
+    }
   }
 };
diff --git a/src/content/Preferences.js b/src/content/Preferences.js
index cb5955e..7780340 100644
--- a/src/content/Preferences.js
+++ b/src/content/Preferences.js
@@ -215,8 +215,7 @@ com.gContactSync.Preferences = {
     numRelations:             new com.gContactSync.Pref("numRelations",              "int", 6),
     numLogsInRotation:        new com.gContactSync.Pref("numLogsInRotation",         "int", 3),
     selectFirstCardAfterDrop: new com.gContactSync.Pref("selectFirstCardAfterDrop", "bool", true),
-    notesHeight:              new com.gContactSync.Pref("notesHeight",              "char", ""),
-    authenticationPort:       new com.gContactSync.Pref("authenticationPort",        "int", 80)
+    notesHeight:              new com.gContactSync.Pref("notesHeight",              "char", "")
   },
   /**
    * Gets a preference given its branch, name, and type
diff --git a/src/content/gdata.js b/src/content/gdata.js
index e8c47c6..783e6a6 100644
--- a/src/content/gdata.js
+++ b/src/content/gdata.js
@@ -55,7 +55,8 @@ false);
 com.gContactSync.gdata = {
   CLIENT_ID:                  "874495714229-5m7jmsjebv6nrf61q14siutq43bi1gvt.apps.googleusercontent.com",
   CLIENT_SECRET:              "vayAK3lt9f4tMcMK1HZ4XZqG",
-  REDIRECT_URI:               "http://localhost",
+  REDIRECT_URI:               "urn:ietf:wg:oauth:2.0:oob",
+  REDIRECT_TITLE:             "Success code=",
   RESPONSE_TYPE:              "code",
   SCOPE:                      "https://www.google.com/m8/feeds",
   OAUTH_URL:                  "https://accounts.google.com/o/oauth2/auth",
@@ -82,7 +83,6 @@ com.gContactSync.gdata = {
            "?response_type=" + com.gContactSync.gdata.RESPONSE_TYPE +
            "&client_id=" + com.gContactSync.gdata.CLIENT_ID +
            "&redirect_uri=" + com.gContactSync.gdata.REDIRECT_URI +
-           ":" + com.gContactSync.Preferences.mSyncPrefs.authenticationPort.value +
            "&scope=" + com.gContactSync.gdata.SCOPE +
            "&login_hint=" + aEmail;
   },
diff --git a/src/defaults/preferences/gContactSync.js b/src/defaults/preferences/gContactSync.js
index 017cd5d..23d2a6c 100644
--- a/src/defaults/preferences/gContactSync.js
+++ b/src/defaults/preferences/gContactSync.js
@@ -99,8 +99,6 @@ pref("extensions.gContactSync.numLogsInRotation", 3);
 pref("extensions.gContactSync.selectFirstCardAfterDrop", true);
 // The style for the notes field in the edit contact dialog
 pref("extensions.gContactSync.notesHeight", "");
-// The port used for the redirect_uri during OAuth
-pref("extensions.gContactSync.authenticationPort", 80);
 // extended properties to sync
 pref("extensions.gContactSync.extended1", "Custom1");
 pref("extensions.gContactSync.extended2", "Custom2");
diff --git a/src/locale/en-US/options.dtd b/src/locale/en-US/options.dtd
index cf49c80..667d4a4 100644
--- a/src/locale/en-US/options.dtd
+++ b/src/locale/en-US/options.dtd
@@ -57,8 +57,6 @@
 <!ENTITY httpRequestTimeout.accesskey     "H">
 <!ENTITY httpRequestDelay.value           "Delay between HTTP requests (ms, 0 to disable) [100]">
 <!ENTITY httpRequestDelay.accesskey       "l">
-<!ENTITY authenticationPort.value         "Authentication port [80]">
-<!ENTITY authenticationPort.accesskey     "A">
 <!ENTITY resetAll.label                   "Reset All Synced ABs">
 <!ENTITY resetAll.accesskey               "R">
 <!ENTITY cleanOldPrefs.label              "Clean Old AB Preferences">

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/gcontactsync.git



More information about the Pkg-mozext-commits mailing list