Reputation: 7215
I currently use Devise 2.1 + Rails 3.2.x to authenticate users. I'm also going to be adding OmniAuth-Facebook and Twitter support soon.
I wanted to use this existing infrastructure with Backbone.js. Can you let me know if this is the correct workflow from authentication perspective?
Questions: 1. Is this how you'd implement it? 2. Any suggestions/code samples on #2 and #3? 3. How would you handle authorization with this? I don't think CanCan will work.
P.S. I read through many articles, including this: http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise/. They seem to be focused on authentication using the API, rather than securing the API resources after authentication is completed.
Upvotes: 5
Views: 2146
Reputation: 7215
I actually got this to even a little easier by:
User logs in via Devise/OmniAuth, no authentication token needs to be created If I use the same action that is Devise enabled to serve up the REST API, it'll automatically use the session info to authenticate, so no additional token capture/resend is needed.
P.S. RABL is generate for creating API's in Rails.
Upvotes: 2
Reputation: 18347
Backbone.sync
, or if you're using jQuery you can confiugure jQuery globally. Example hereAuthorization would be handled the same on the server side, unless you want the client to know about its roles. On the server side, you'll find the current user via its token and authorize accordingly. If you do need to know what roles a user have, you can send the roles when the user authenticates.
Upvotes: 0