Skip to content

Instantly share code, notes, and snippets.

@nnance
Last active January 2, 2016 17:09
Show Gist options
  • Save nnance/8334995 to your computer and use it in GitHub Desktop.
Save nnance/8334995 to your computer and use it in GitHub Desktop.
Backbone authentication by passing tokens as query params
define(function (require) {
"use strict";
var Backbone = require('backbone');
return Backbone.Model.extend({
initialize: function() {
this.backboneAjax = Backbone.ajax;
},
initAuthentication: function(user) {
var backboneAjax = this.backboneAjax;
Backbone.ajax = function () {
var initChar = arguments[0].url.indexOf('?') > 0 ? '&' : '?';
arguments[0].url += initChar + 'userid=' + user.id + '&userkey=' + user.get('key');
return backboneAjax.apply(this, arguments);
};
},
removeAuthentication: function() {
Backbone.ajax = this.backboneAjax;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment