Skip to content

Instantly share code, notes, and snippets.

@lloydwatkin
Created January 17, 2013 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloydwatkin/4556860 to your computer and use it in GitHub Desktop.
Save lloydwatkin/4556860 to your computer and use it in GitHub Desktop.
Hack to backbone.js to get buddycloud webclient + http api server + tigase (+ buddycloud java server) talking.
@@ -1418,9 +1419,18 @@
// Make the request, allowing the user to override any Ajax options.
return Backbone.ajax(_.extend(params, options));
};
-
+var credentials;
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
Backbone.ajax = function() {
+ if (arguments[0].credentials) {
+ console.log("Storing credentials", arguments[0].credentials);
+ credentials = arguments[0].credentials;
+ } else if (credentials) {
+ arguments[0].credentials = credentials;
+ arguments[0].xhrFields = {withCredentials: true}
+ console.log("Setting credentials", arguments);
+ }
return Backbone.$.ajax.apply(Backbone.$, arguments);
};
@lloydwatkin
Copy link
Author

What I found was that request #1 from the weblclient was passing authentication details through as expected.

The 2nd - 4th requests were not passing through credentials and so new sessions were attempting to be created with a jid of "@hostname" rather than "user@hostname".

Please be aware that I'm running a setup much different to the standard with buddycloud:

  • buddycloud java server (latest)
  • Tigase XMPP server (latest)
  • HTTP API (latest)
  • Webclient (latest)

... to add to this, my stack is running on ec2, all apart from the java server which is running on my local machine with ports forwarded as required. Therefore the response the webclient sees is going to be a little slower than normal. I wonder if on the production/standard setup everything replies fast enough in order that the API calls get their token for the next request?

@lloydwatkin
Copy link
Author

I never seem to get the X-Session-Id set by the webclient, i.e. loads-and-loads-and-loads of new sessions!

^^^^^ this may be a consequence of hack

@imaginator
Copy link

sessionID stuff is a bit broken right now. There's an issue open for addressing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment