What approaches can we use to cleanly provide access to both API clients and regular users in a Rails application?
-
We're building a Rails 3 web application that will need to authorize and authenticate regular users who visit the site. Those same users may also use third-party applications to access the site via our API. What approaches can we use to effectively and cleanly provide access to clients as well as users? What strategies have you used in your own Rails applications that also have RESTful APIs? Ideally, we're after a solution which: plays well with Devise and CanCan (which we already use for authn/authz) plays well with Mongoid doesn't pollute our controllers is relatively simple to install and configure, if it's a gem or plugin
-
Answer:
I'm a relative newcomer to Ruby and Rails, but have been doing software development in various languages for over 20 years, and web development for about as long as the web has been around. That said, it seems to me that the best strategy would be to put your business logic into services, rather than what seems to be the standard practice of putting it in the controllers. Then, your controllers can just do authn/authz, and delegate the business logic to the services. You'll likely have different controllers for the browser users vs. the API, but they can share the business logic implemented by the services. This is a fairly standard approach in other languages/frameworks.
Rich Freedman at Quora Visit the source
Other answers
Devise has built in support for token authentication, you can provide your user with an auth token much like a lot of other Apis out there so ur user will have a key and secret the secret is the token devise generated and the key I'd the I'd of the user it's called single sign on. So u still have 1 users table and 1 identity.
Sakchai Grouch Siripanyawuth
Related Q & A:
- What else can I use instead of PayPal?Best solution by searchenginejournal.com
- Can I use my Germany-Austria Eurail pass to travel from rome to Munich on a City Night Line overnight train?Best solution by Yahoo! Answers
- What else can you use to clean the metal part of the Oreck XL air cleaner besides their Assail-A-Cell?Best solution by Yahoo! Answers
- What card can I use with Paypal?Best solution by banking.about.com
- What monitor can I use with a mac mini?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.