我想用rails后端构建一个iOS应用程序。我选择了devise作为用户认证和会话管理系统。iOS,rails,设计:如何保持用户登录(session vs authentication_token)
目前我已经修改了最初的Devise RegistrationsController和SessionsController,以便它们返回JSON响应。样品创建SessionsController方法如下:
def create
build_resource
if resource.save
if resource.active_for_authentication?
sign_up(resource_name, resource)
respond_to do |format|
format.json { render :json => ["success", resource, User.serialize_into_cookie(resource)]}
end
else
expire_session_data_after_sign_in!
respond_to do |format|
format.json { render :json => ["inactive", resource]}
end
end
else
clean_up_passwords resource
respond_to do |format|
format.json { render :json => ["error", resource]}
end
end
end
我想知道什么是最好的方式坚持通过登录iOS应用程序是。
大多数的设计教程只是针对web应用程序,我不知道我应该如何将这些应用程序应用到我的iOS应用程序。
我正在使用的框架是'AFNetworking',而我用于联网的类是'AFHTTPClient'和'AFJSONRequestOperation'。但我不知道如何在客户端检索和存储会话,以便稍后使用它。
也许我应该使用不同的网络框架,使用适当的标题和东西来检索会话和cookie?像ASIHTTPClient的东西?
或者我应该在设计中使用token_authenticatable功能来保持登录?
'TokenAuthenticatable'现在已经[从Devise中删除](https://github.com/plataformatec/devise/issues/2739),看到替代品[here](https://github.com/plataformatec/devise/维基/操作方法: - 简单,令牌的认证-例)。 – dukedave 2014-08-12 17:14:43