9

I have integrated Devise and OmniAuth with my Mongoid ORM setup using the following examples:

https://github.com/plataformatec/devise/wiki/Example-Applications

My client code is mostly JavaScript (ExtJS) and relies on JSON for all of the communication. I use no Rails templates. I am looking to build a multi-provider authentication model, primarily using user/pass, Facebook, and Twitter. I am having difficulty putting together the full User authentication flow with respect to my application stack.

I am looking for an example that uses JSON responses to the standard authentication actions, instead of redirects, and provides an integration with OmniAuth that uses Mongoid. In addition to the above examples, I have gone through Ryan Bates' Railscasts on Devise and OmniAuth. Every example I have worked through so far have either been ActiveRecord, or Rails template oriented. Any pointers are appreciated!

2 Answers 2

4

This (https://github.com/fertapric/rails3-mongoid-devise-omniauth) is a good example app for getting set up with rails 3, devise, omniauth and mongoid, and a tutorial to go along with it here: https://github.com/fortuity/rails3-mongoid-devise/wiki/Tutorial-(Walkthrough)

Then you'll need to override the user sessions controller to provide the correct json responses for your app, there is a good example here: https://gist.github.com/733647 and here: http://groups.google.com/group/plataformatec-devise/browse_thread/thread/daa3332b3c4a1b4b

Hope this helps

2
  • Andrew, sorry for the delay in accepting an answer. Back in December, when I asked the question, I crafted a solution that worked pretty well. I used some the pointers you have listed here, but that still left me with a number of issue to overcome. I intended to document and post it here, but things changed over the passing months making my solution obsolete. Jul 14, 2011 at 17:17
  • 1
    @MikeClymer My Rails App has Web and Mobile app interface. Mobile app interface is developed in Sencha Touch and interacts with Rails App completely through AJAX/JSON. I am using Devise+OmniAuth combo for authentication, and I am stuck at how to enable login through Facebook/Google from phone app interface using AJAX/JSON. You seem to have figured it out, it would be great if you could please share your solution with me. Let me know if I should create a new Question on SO for this, so that I could accept your answer when you reply to that. Thanks.
    – Zeeshan
    Oct 12, 2011 at 12:05
0

I would suggest that you roll your own authentication mechanism using Rails 3.1 ActiveModel::SecurePassword instead of using Devise. You will get a cleaner solution that way than trying to tweak Devise to provide JSON responses.

If you can't use Rails 3.1, I would still suggest that you roll your own instead of overriding an internal Devise method (which the gist that Nesbitt links to does).

1
  • Peder, I appreciate what Rails 3.1 is doing with ActiveModel::SecurePassword. It promotes the use of bcrypt, which is a good thing. AFAIK, it is relatively easy to configure Devise to use bcrypt as its encryption mechanism. Migrating existing users can create issues, but that is another topic. ActiveModel::SecurePassword doesn't actually provide a robust auth framework that includes features like role integration, email verification, remember me tokens, and multiple auth account management. I see no reason to roll my own, when I can get all of these features and make use of bcrypt in Devise. Jul 14, 2011 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.