From d5eb389fb5324ca085057d46086e19c5916fd7cc Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Thu, 22 Dec 2011 09:06:34 -0700
Subject: [PATCH] add plumbing to redirect to IdP and back for auth

---
 lib/browserid/views.js                        | 4 ++++
 resources/static/auth_with_idp/main.js        | 7 +++++++
 resources/static/pages/signup.js              | 8 +++++---
 resources/views/authenticate_with_primary.ejs | 9 +++++++++
 4 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 resources/static/auth_with_idp/main.js
 create mode 100644 resources/views/authenticate_with_primary.ejs

diff --git a/lib/browserid/views.js b/lib/browserid/views.js
index f1d582c46..de23cb846 100644
--- a/lib/browserid/views.js
+++ b/lib/browserid/views.js
@@ -47,6 +47,10 @@ exports.setup = function(app) {
     });
   });
 
+  app.get("/authenticate_with_primary", function(req,res, next) {
+    res.render('authenticate_with_primary.ejs', { layout: false });
+  });
+
   app.get('/', function(req,res) {
     res.render('index.ejs', {title: 'A Better Way to Sign In', fullpage: true});
   });
diff --git a/resources/static/auth_with_idp/main.js b/resources/static/auth_with_idp/main.js
new file mode 100644
index 000000000..ee08277d3
--- /dev/null
+++ b/resources/static/auth_with_idp/main.js
@@ -0,0 +1,7 @@
+var wc = WinChan.onOpen(function(origin, args, cb) {
+  if (window.location.hash === '#complete') cb();
+  else {
+    wc.detach();
+    window.location = args;
+  }
+});
diff --git a/resources/static/pages/signup.js b/resources/static/pages/signup.js
index 1a1853470..0e327c8d0 100644
--- a/resources/static/pages/signup.js
+++ b/resources/static/pages/signup.js
@@ -62,7 +62,7 @@ BrowserID.signUp = (function() {
 
       var url = helpers.toURL(verifyURL, {
           email: verifyEmail,
-          return_to: "https://browserid.org/idp_auth_complete"
+          return_to: "https://browserid.org/authenticate_with_primary#complete"
       });
 
       // XXX: we should use winchan (and send user to a page that redirects to primary)!
@@ -78,11 +78,13 @@ BrowserID.signUp = (function() {
       //    silently provision again!  success means the users is signed up, failure
       //    means there was an auth problem.  they can try again?
       var win = winchan.open({
-        url: url,
+        url: "https://browserid.org/authenticate_with_primary",
         // This is the relay that will be used when the IdP redirects to sign_in_complete
         relay_url: "https://browserid.org/relay",
-        window_features: "width=700,height=375"
+        window_features: "width=700,height=375",
+        params: url
       }, primaryAuthComplete);
+
       oncomplete && oncomplete();
     }
 
diff --git a/resources/views/authenticate_with_primary.ejs b/resources/views/authenticate_with_primary.ejs
new file mode 100644
index 000000000..bfdc57972
--- /dev/null
+++ b/resources/views/authenticate_with_primary.ejs
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Browser ID</title>
+  <script type='text/javascript' src='https://browserid.org/lib/winchan.js'></script>
+  <script type='text/javascript' src='https://browserid.org/auth_with_idp/main.js'></script>
+</head>
+</html>
-- 
GitLab