Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile App webframe Authentication with Rails Devise

I am currently working on implementing a mobile app for our site that uses Ruby on Rails and Devise. The idea here is, at first, create a mobile login form that on successful login opens a web frame that is authenticated and allows the normal use of the (mobile optimised) site. Theoretically that should be possible. I am having trouble with the following issues:

  1. How do you get the pure session key for the user session via a json request? What methods can be used to manually generate it from devise, something that the sign_in(:user, user) method does?

  2. Is it even possible to take that key and put it into the browser cookie the way it normally happens in devise, but on the mobile side?

I know that this is not the standard method of making mobile applications for the site, but I believe it should be possible.

like image 419
Vitaly Stanchits Avatar asked Jun 08 '16 19:06

Vitaly Stanchits


1 Answers

You might want to consider using Devise Token Auth and treating your mobile application like just another webapp that requests permission from your main site. DTA is particularly nice since it takes care of managing the session tokens (renewing/expiring) and passing them onto the app requiring access. The issue is overriding your session controllers so that it automatically logs in after you already log in on the mobile app (or just rewriting your log in so it occurs in conjunction with the Rails site, rather than before). Considering you're already using Devise, this may also be more refactoring than you'd like.

like image 179
Raynor Kuang Avatar answered Sep 29 '22 11:09

Raynor Kuang