I’m trying to build a mobile application with PhoneGap, jQuery Mobile and Backbone.js on the client-side – with a Rails 3 JSON API running server-side.
I know how to fetch the token from the server after being authenticated, but I don’t know how to append the “token_auth” key/value to all the AJAX-requests Backbone.js will make to my server.
Here’s my flow at the moment:
- User types in some form fields and hits “Log in”
- Backbone creates a new Player object with the email and password info.
- I run a Player.authenticate that sets the token to AUTHENTICATION_TOKEN
- All requests after this should append “auth_token=” + AUTHENTICATION_TOKEN
I’ve looked at http://documentcloud.github.com/backbone/#Sync for maybe overriding the AJAX calls – but that seems quite extreme for this simple task.
Does anyone have any experience with running Devise token_authentication and Backbone.js?
Why don’t append it to all of your jquery ajax requests. It will add the auth_token to all of your ajax calls over jQuery. That might be useful when working directly with jQuery ajax (or libs that do so). But this might be a security issue as well (when you have ajax calls to other sites…).
Another approach may be to write that token into the header and process it on the server side: