API authentication

Dana Hartweg
Jul 26, 2013 · 2 min read

In creating a consumable REST API, authenticating users is a must. I’m using the rails-api gem, which removes a lot of the extra rails components you have no need for in an API-only application. The API will be consumed by a separate web app (powered by Ember JS in this case), or mobile application.

The problem

I’m going to say it. I really wanted to use Devise to handle my authentication. It has most everything you could want built right in. Others, such as Omni-Auth support to handle Google and Facebook, are easily added. All in all, Devise is a great solution if you’re running a full blown rails app. When using the rails-api gem, it seemed as if I was fighting Devise every step of the way, and spending way too much time doing so. In the end, I decided to ditch Devise for this API.

Luckily, I found this great resource from Eric Berry that was an excellent start for me. You can find my project (changes / features are listed on the GitHub project page), as well as a few resources I found along the way, below.

Excellent resources

Rails-Api project | gem that strips down your rails installation to only the basics needed for an API-only application

Scott W. Bradley, Revisited: Adding Filters to Stock Devise Controllers | method for inserting a `before_filter` to a Devise (or other gem) controller (I was attempting to use this method to add CORS header support to Devise)

Eric Berry, Authentication With EmberJS | walkthrough on creating both a back-end API (with authentication) and Ember application to consume it

Brian Cardarella, Building an Ember app with RailsAPI | another walkthrough for creating an API and Ember application

GitHub project

You can find the project on GitHub. It’s using Unicorn, and ready to be deployed to Heroku.

If you see anything I did blatantly wrong, I’d love to hear about and learn from it!

Originally published at danahartweg.com on July 26, 2013.

    Dana Hartweg

    Written by

    Senior Front End Software Engineer, InVision Studio

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade