How to let Rails tell mobile applications that users signed in or not?

旧巷老猫 提交于 2019-12-25 02:14:06

问题


I'm developing a Rails application that use devise as the authentication solution. For web applications, users enter username and password in a form, Rails can render different pages after users signed in.

Now I'd like to use this framework to support mobile app. In this case, the mobile app needs to know whether the user enters correct username and password.

How should devise response to the mobile application, response headers or JSON inside body? Does devise support it?


回答1:


You need token authentication. Mobile client should have a login form and access the REST API for authentication. If authentication was successful, you will get a token which you need to send with all the subsequent requests in the same session.

http://zyphdesignco.com/blog/simple-auth-token-example-with-devise

http://matteomelani.wordpress.com/2011/10/17/authentication-for-mobile-devices/




回答2:


More tutorials:

http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-devise/

http://www.strukturedkaos.com/2011/09/19/soup-to-nuts-token-authentication-for-android-using-rails-3-devise/

Make sure to enable/uncomment the following line in devise configuration:

config.token_authentication_key = :auth_token


来源:https://stackoverflow.com/questions/13243496/how-to-let-rails-tell-mobile-applications-that-users-signed-in-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!