我想开始研究我对 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
一些资源可以帮助您一路走来:
希望能有所帮助!
关于ruby-on-rails - Rails3 应用程序的起点,它将成为 iphone 应用程序的后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7003179/