diff --git a/resources/static/auth_with_idp/main.js b/resources/static/auth_with_idp/main.js
index d0ee9697a5a33baa76ef2347b2ba98baff13352b..0e759ca4906d124c2fca95397d22e5ad5bfeef79 100644
--- a/resources/static/auth_with_idp/main.js
+++ b/resources/static/auth_with_idp/main.js
@@ -5,7 +5,13 @@
 var wc = WinChan.onOpen(function(origin, args, cb) {
   if (window.location.hash === '#complete') cb();
   else {
+    var fullURL = args;
+
+    // store information in window.name to indicate that
+    // we redirect here
+    window.name = 'auth_with_primary';
+
     wc.detach();
-    window.location = args;
+    window.location = fullURL;
   }
 });
diff --git a/resources/static/authentication_api.js b/resources/static/authentication_api.js
index ca9b16c49990977dac2d828dacfdf2a9ea669571..8e2a0e98b775cb4167c2f41cfc406e9f1f283013 100644
--- a/resources/static/authentication_api.js
+++ b/resources/static/authentication_api.js
@@ -33,11 +33,17 @@
     };
 
     navigator.id.completeAuthentication = function(cb) {
-      window.location = 'https://login.persona.org/sign_in#AUTH_RETURN';
+      if (window.name == 'auth_with_primary')
+        window.location = 'https://login.persona.org/authenticate_with_primary#complete';
+      else
+        window.location = 'https://login.persona.org/sign_in#AUTH_RETURN';
     };
 
     navigator.id.raiseAuthenticationFailure = function(reason) {
-      window.location = 'https://login.persona.org/sign_in#AUTH_RETURN_CANCEL';
+      if (window.name == 'auth_with_primary')
+        window.location = 'https://login.persona.org/authenticate_with_primary#complete';
+      else
+        window.location = 'https://login.persona.org/sign_in#AUTH_RETURN_CANCEL';
     };
 
     navigator.id._primaryAPIIsShimmed = true;
diff --git a/resources/static/pages/js/page_helpers.js b/resources/static/pages/js/page_helpers.js
index 47389799d5ef8393901c8132a2b9751a28b5a6c7..758f4df8eab7ad4cb3393bb7142735c41e8c1419 100644
--- a/resources/static/pages/js/page_helpers.js
+++ b/resources/static/pages/js/page_helpers.js
@@ -136,17 +136,12 @@ BrowserID.PageHelpers = (function() {
       throw "cannot verify with primary without an email address and URL"
     }
 
-    var url = helpers.toURL(baseURL, {
-        email: email,
-        return_to: "https://login.persona.org/authenticate_with_primary#complete"
-    });
-
     winchan.open({
       url: "https://login.persona.org/authenticate_with_primary",
       // This is the relay that will be used when the IdP redirects to sign_in_complete
       relay_url: "https://login.persona.org/relay",
       window_features: "width=700,height=375",
-      params: url
+      params: helpers.toURL(baseURL, {email: email})
     }, function(error, result) {
       // We have to force a reset of the primary caches because the user's
       // authentication status may be incorrect.