Last active
January 2, 2016 17:09
-
-
Save nnance/8334995 to your computer and use it in GitHub Desktop.
Backbone authentication by passing tokens as query params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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