faking browseridaccess flow
authorMichiel de Jong <michiel@unhosted.org>
Fri, 23 Dec 2011 03:42:57 +0000 (10:42 +0700)
committerMichiel de Jong <michiel@unhosted.org>
Fri, 23 Dec 2011 03:42:57 +0000 (10:42 +0700)
README.md
controller.js
webfinger.js

index 2e067d0..3505add 100644 (file)
--- a/README.md
+++ b/README.md
@@ -11,12 +11,12 @@ The following options can be passed either as a js object inside the script tag,
         <meta charset="utf-8">
         <title>example</title>
         <script src="http://unhosted.org/remoteStorage.js">{
-          foo: 'bar'
+          someKey: 'someValue'
         }</script>
         <script>
           function changeFoo() {
             remoteStorage.configure({
-              foo: 'baz'
+              someKey: 'someNewValue'
             });
           }
         </script>
@@ -34,6 +34,7 @@ Options:
 * suppressDialog: if false, a dialog is displayed. if true, you should call configure() with userAddress yourself to initiate connection.
 * userAddress: when you do your own login interface, use this with configure() to initiate connection.
 * suppressAutoSave: if false, localStorage is diffed and synced every 5 seconds. if true, you should call remoteStorage.syncNow() each time you want changes to be pushed
+* requestBrowseridAccess: experimental; see http://groups.google.com/group/unhosted/browse\_thread/thread/8665a5913ccbd965
 
 Methods:
 
index 86631b0..fb12a4f 100644 (file)
@@ -49,11 +49,19 @@ define([
       });
     }
   }
+  function getBrowseridAccess(url, assertion, audience, cb) {
+    ajax.ajax({
+      url: url,
+      method: 'POST',
+      data: 'assertion='+encodeURIComponent(assertion)+'&audience='+audience,
+      success: cb
+    });
+  }
   function connectTo(userAddress) {
     webfinger.getAttributes(userAddress, {
       allowHttpWebfinger: true,
       allowSingleOriginWebfinger: false,
-      allowFakefinger: true
+      allowFakefinger: false
     }, onError, function(attributes) {
       var backendAddress = webfinger.resolveTemplate(attributes.template, options.category);
       if(attributes.api == 'CouchDB') {
@@ -66,7 +74,21 @@ define([
         console.log('API "'+attributes.api+'" not supported! please try setting api="CouchDB" or "WebDAV" or "simple" in webfinger');
       }
       session.set('backendAddress', backendAddress);
-      oauth.go(attributes.auth, options.category, userAddress);
+      if(options.requestBrowseridAccess && options.assertion && options.audience && attributes.browseridAccess) {
+        console.log('going with browserid access');
+        //set backend
+        var backendName = localStorage.getItem('_shadowBackendModuleName')
+        if(backendName) {
+          require(['./' + backendName], function(backendObj) {
+            afterLoadingBackend(backendObj);
+            getBrowseridAccess(attributes.browseridAccess, options.assertion, options.audience, withToken);
+          });
+        } else {
+          console.log('we got no backend');
+        }
+      } else {
+        oauth.go(attributes.auth, options.category, userAddress);
+      }
     });
   }
   function disconnect() {
@@ -104,16 +126,22 @@ define([
       button.show(isConnected, userAddress);
     }
   }
-  function afterLoadingBackend(backendObj) {
-    oauth.harvestToken(function(token) {
-      session.set('token', token);
-      if(backendObj) {
+  function withToken(token) {
+    session.set('token', token);
+    var backendName = localStorage.getItem('_shadowBackendModuleName')
+    if(backendName) {
+      require(['./' + backendName], function(backendObj) {
         backendObj.init(session.get('backendAddress'), token);
         console.log('set backendObj');
-      }
-      options.onStatus({name: 'disconnected'}, {name: 'online'});
-      sync.start();
-    });
+      });
+    } else {
+      console.log('got no backend in withToken');
+    }
+    options.onStatus({name: 'disconnected'}, {name: 'online'});
+    sync.start();
+  }
+  function afterLoadingBackend(backendObj) {
+    oauth.harvestToken(withToken);
     sync.setBackend(backendObj);
     if(options.suppressAutoSave) {
       console.log('suppressing autosave');
index b2b7146..9cb02af 100644 (file)
@@ -205,6 +205,9 @@ define(['./ajax'], function(ajax) {
               if(attr2.name=='api') {
                 attributes.api = attr2.value;
               }
+              if(attr2.name=='browseridaccess') {
+                attributes.browseridAccess = attr2.value;
+              }
             }
             break;
           }