如何让Rails告诉用户login的移动应用程序?

我正在开发一个使用devise作为身份validation解决scheme的Rails应用程序。 对于Web应用程序,用户在表单中input用户名和密码,Rails可以在用户login后呈现不同的页面。

现在我想用这个框架来支持移动应用程序。 在这种情况下,移动应用程序需要知道用户是否input正确的用户名和密码。

如何devise响应的移动应用程序,响应标题或JSON体内? devise支持吗?

你需要令牌authentication。 移动客户端应具有login表单并访问REST API进行身份validation。 如果validation成功,您将获得一个令牌,您需要在同一会话中发送所有后续请求。

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

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

更多教程:

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/

请确保在deviseconfiguration中启用/取消注释以下行:

config.token_authentication_key = :auth_token