ruby-on-rails - Rails3 应用程序的起点,它将成为 iphone 应用程序的后端

标签 ruby-on-rails ruby-on-rails-3 api devise omniauth

我想开始研究我对 iphone 应用程序的想法,但我在从哪里开始时遇到了一些问题。我希望该应用程序主要在 iphone 上使用,但在网络应用程序上具有一些功能,例如登录和查看从 iphone 应用程序创建的内容。我已经启动了一个 rails3 应用程序,并希望将其用作 api/app 的后端。

我对如何使用身份验证系统感到困惑,以便该应用程序既可以用作 Web 应用程序,也可以用作 iphone 应用程序的 api。

我想在 web 和 iphone 应用程序上使用omniauth 登录,因为我只希望用户使用 twitter 和/或 fb 登录,但是一旦用户登录到 iPhone 应用程序,我不知道如何验证请求。我知道像 devise 之类的其他一些 gem 允许使用 api key 可验证列之类的东西,这使得签名 api 调用更容易,但我认为它的身份验证系统过于臃肿而无法使用。

任何人都可以就如何制作一个既可以作为 web 应用程序工作又可以通过 iphone 通过 api 进行身份验证的身份验证系统给我建议。

谢谢!

最佳答案

一些想法...

我假设只是让 iOS 应用程序的行为类似于网络浏览器,并像往常一样发送一个持久性 cookie 以及每个请求。通过这种方式,您可以使用标准的身份验证做法,也可以让自己在某天发布基于 Web 的应用程序版本,而无需彻底检查所有内容。

所以工作流程是:

  • Get authentication information from user input and save securely in the Keychain to seamlessly log them in every time they open the app
  • Use something like Devise to do the Rails server-side authentication (i.e. don't reinvent the wheel)
  • POST the data to the server to create a new session
  • Receive the session information back from the server in the form of a cookie
  • Store the cookie in the iOS app
  • Send the cookie information back to the server with every request
  • If they log out, destroy the cookie and the keychain data you stored to create the cookie every time they opened the app


NSURLConnection 提供了一种方法来完成大部分工作,甚至只要您不告诉它不要发送任何存储的 cookie 以及请求。这是一篇旧的 SO 帖子,讨论了其中的一些内容:Objective-C Asynchronous Web Request with Cookies

一些资源可以帮助您一路走来:
  • 获取/存储/发送cookies:http://www.calaresu.eu/2011/06/01/using-cookies-with-cocoa-nshttpcookie/
  • 关于带有 Rails 的 iPhone 的精彩幻灯片:http://www.slideshare.net/maximeguilbot/rails-as-ios-application-backend
  • 适合在 iOS 上的 Keychain 中存储身份验证信息:https://github.com/ldandersen/scifihifi-iphone
  • 与 Rails 应用程序交谈:http://restkit.org/ (和 here's a rails example )

  • 希望能有所帮助!

    关于ruby-on-rails - Rails3 应用程序的起点,它将成为 iphone 应用程序的后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7003179/

    相关文章:

    ruby-on-rails - PaperTrail : info_for_paper_trail outside the context of a controller

    API、工具包、框架、库

    api - Mailchimp API merge_var 地址...如何创建城市列表?

    ruby-on-rails - 标题标签在 Rails/HAML 中被转义两次

    ruby-on-rails - rails : Check uniqueness of decrypted data

    ruby-on-rails - 如何在 Rails 中将图像转换为链接?

    json - 对于 Restful API,GET 方法可以使用 json 数据吗?

    html - Rails form_tag 未显示

    ruby-on-rails - rails ActiveSupport :Concern and Private Methods

    ruby-on-rails-3 - 带有 RABL 的 Rails 3 API