Author: hsaputra
Date: Tue Sep 13 22:39:09 2011
New Revision: 1170371

URL: http://svn.apache.org/viewvc?rev=1170371&view=rev
Log:
SHINDIG-1580 | Allow for custom security token fetch function to be used when 
refreshing security tokens | Improvement Patch from Jesse Ciancetta

CR: https://reviews.apache.org/r/1564


Modified:
    shindig/trunk/features/src/main/javascript/features/container/container.js
    shindig/trunk/features/src/main/javascript/features/container/service.js

Modified: 
shindig/trunk/features/src/main/javascript/features/container/container.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=1170371&r1=1170370&r2=1170371&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js 
(original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js 
Tue Sep 13 22:39:09 2011
@@ -474,6 +474,11 @@ osapi.container.ContainerConfig.GET_PREF
  * @type {function}
  */
 osapi.container.ContainerConfig.SET_PREFERENCES = 'SET_PREFERENCES';
+/**
+ * Used to retrieve security tokens for gadgets.
+ * @type {function}
+ */
+osapi.container.ContainerConfig.GET_GADGET_TOKEN = 'GET_GADGET_TOKEN';
 
 
 // 
-----------------------------------------------------------------------------

Modified: 
shindig/trunk/features/src/main/javascript/features/container/service.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/service.js?rev=1170371&r1=1170370&r2=1170371&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/service.js 
(original)
+++ shindig/trunk/features/src/main/javascript/features/container/service.js 
Tue Sep 13 22:39:09 2011
@@ -28,7 +28,7 @@
  * @constructor
  */
 osapi.container.Service = function(opt_config) {
-  var config = opt_config || {};
+  var config = this.config_ = opt_config || {};
 
   /**
    * @type {string}
@@ -202,19 +202,18 @@ osapi.container.Service.prototype.update
  * @param {Object} request JSON object representing the request.
  * @param {function(Object)=} opt_callback function to call upon data receive.
  */
-osapi.container.Service.prototype.getGadgetToken = function(
-    request, opt_callback) {
+osapi.container.Service.prototype.getGadgetToken = function(request, 
opt_callback) {
   var callback = opt_callback || function() {};
 
   // Do not check against cache. Always do a server fetch.
   var self = this;
-  osapi['gadgets']['token'](request).execute(function(response) {
+  var tokenResponseCallback = function(response) {
     var finalResponse = {};
 
     // If response entirely fails, augment individual errors.
     if (response['error']) {
       for (var i = 0; i < request['ids'].length; i++) {
-        finalResponse[id] = { 'error' : response['error'] };
+        finalResponse[request['ids'][i]] = { 'error' : response['error'] };
       }
 
     // Otherwise, cache response. Augment final response with server response.
@@ -227,7 +226,14 @@ osapi.container.Service.prototype.getGad
     }
 
     callback(finalResponse);
-  });
+  };
+
+  // If we have a custom token fetch function, call it -- otherwise use the 
default
+  if (this.config_[osapi.container.ContainerConfig.GET_GADGET_TOKEN]) {
+    this.config_[osapi.container.ContainerConfig.GET_GADGET_TOKEN](request, 
tokenResponseCallback);
+  } else {
+    osapi['gadgets']['token'](request).execute(tokenResponseCallback);
+  }
 };
 
 


Reply via email to