我想用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