Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the new Devise for authentication for a mobile app

I am trying to implement user authentication using Devise for my Rails/iOS app. I am having trouble since I've mostly been a "user" of Devise and was using it for pure web apps so didn't need to bother so much with what goes on behind the scenes. Now that I have to build authentication for an API based app, it's entirely a different world.

I've read every single tutorial on the web that deals with this topic (most of them are outdated due to the fact that token_authenticatable has been deprecated) but still having trouble understanding what I need to do.

I also read the original GitHub gist talking about this issue and still don't understand what they are talking about.

I'm sure there are people out there just like me who've been just a "user" of Devise so don't really know what goes on behind the scenes.

Can anyone provide a concise solution to implementing an API based authentication system for a mobile app? I mean it can't be that complex, Devise used to be so awesome since all i needed to do was run rails generate, but this has been nightmare for me.

like image 840
Vlad Avatar asked Jan 21 '14 03:01

Vlad


People also ask

How does devise gem work?

Devise is the cornerstone gem for Ruby on Rails authentication. With Devise, creating a User that can log in and out of your application is so simple because Devise takes care of all the controllers necessary for user creation ( users_controller ) and for user sessions ( users_sessions_controller ).


2 Answers

I am working on same things as you want,

for this you have to use token authentication rather than simple Devise, add following gem in gemfile

  # Use device for authentication     gem 'devise'     gem 'simple_token_authentication' 

follow documention simple_token_authentication

Use Api like this  curl -v https://example.com/users/sign_in -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d '{"user": {"login": "7838712847" ,"password": "8489", "mobile_type": "ios", "mobile_key": "APA91bG6G4UvjeCWvb8mMAH1ZO3I-8FB3nkRPyCHnwZiXgd16HK18GgoV5n7gjJtZNs038iaFGutzdxnhes3WyaXEX52-xmOyvuEK8S1abBdpuhD9AD5bzLWeu-1Ow_yZRTVg3Nypz1z"}}'  I am using mobile number to login so customize gem according your need 

please let me know if it is not working (mail me: [email protected])

like image 199
Mukesh Avatar answered Sep 24 '22 20:09

Mukesh


Recently, we also had to set up token based authentication for our webapp (for API access) - and we also stumbled upon the fact that it has been removed from Devise.

We went with Simple Token Authentication which worked just beautifully.

like image 23
Alain M. Lafon Avatar answered Sep 23 '22 20:09

Alain M. Lafon