Token based authentication for Rails JSON APIs

user5496955 picture user5496955 · Nov 6, 2015 · Viewed 14.2k times · Source

I make API in rails. For normal authentication we use devise but in API how to implement devise for authentication.

gem 'devise_token_auth'

Someone prefer this this gem for authentication but there are no tutorial available for that. How to implement authenitication in rails api?

Answer

K M Rakibul Islam picture K M Rakibul Islam · Nov 6, 2015

Here is a good tutorial on API authentication with devise_token_auth. Also, the devise_token_auth gem's github page seems to have a very good documentation which should help you get started.

If you are looking for a good tutorial to understand the related concepts, here is one that has a thorough walkthrough of creating a Rails API with token-based authentication (Not using devise_token_auth, but useful to understand the concepts).

I also recommend you to take a look at the JWT (JSON Web Token) which works very well with large scale Rails API. Here is another tutorial that explains how to build Rails API Backed With JWT