iOS,Rails,设计:如何保持用户登录(会话与authentication_token) [英] iOS, rails, devise: How to persist user login (session vs authentication_token)
问题描述
我正在尝试构建带有Rails后端的iOS应用。我选择了devise作为用户身份验证和会话管理系统。
I am trying to build an iOS app with rails backend. I have chosen devise as the user authentication and session management system.
当前,我已经修改了原始的Devise RegistrationsController和SessionsController,以便它们返回JSON响应。 SessionsController中的示例创建方法如下:
Currently I have modified the original Devise RegistrationsController and SessionsController so that they return JSON response. The sample create method in SessionsController is as follows:
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应用持续登录的最佳方法是什么。
What I am wondering is what the best way to persist login through iOS app is.
大多数设计教程仅适用于Web应用程序,我不确定如何将它们应用于我的iOS应用程序。
Most of the devise tutorials are just for web applications and I am not sure how I should apply these to my iOS app.
我使用的框架是 AFNetworking,而我用于联网的类是 AFHTTPClient和 AFJSONRequestOperation。但是我不知道如何在客户端检索和存储会话,以便以后使用。
The framework i am using is 'AFNetworking', and the class I am using for networking is 'AFHTTPClient' and 'AFJSONRequestOperation'. But I don't know how to retrieve and store session on the client side so that I can use it for later.
-
也许我应该为网络使用不同的框架,该框架使用适当的标头和东西来检索会话和cookie?像ASIHTTPClient这样的东西?
Maybe I should use a different framework for networking that uses proper headers and things to retrieve session and cookie? something like ASIHTTPClient?
还是我应该在设计中使用token_authenticatable功能来持久登录?
Or should I use token_authenticatable feature in devise to persist login?
推荐答案
如果您的项目只是json后端,通常最好使用token_authenticatable。 JSON易于使用且易于使用,设计使您可以快速进行设置并为您处理所有一切。
If your project is only a json backend, it is normally preferred that you use token_authenticatable. JSON is easy and clean to work with and devise lets you set that up quickly and handles it all for you.
这篇关于iOS,Rails,设计:如何保持用户登录(会话与authentication_token)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!