如何到iOS / iPhone用户在相同的Web应用程序未来的请求远程Web应用程序,并重新使用身份验证票证验证? [英] How to authenticate iOS/iPhone users with remote web application and re-use authentication ticket in future requests to the same web application?

查看:103
本文介绍了如何到iOS / iPhone用户在相同的Web应用程序未来的请求远程Web应用程序,并重新使用身份验证票证验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立iOS应用程序,我需要能够使认证的请求,为各种数据的一个Rails 3应用程序。 Rails的3个应用程序是使用omniauth和URL如 https://myapp.com/auth/facebook ,例如,验证用户通过Facebook ......一旦认证,存储在一个名为cookie的安全认证验证

我想知道的是如何我的用户从iOS / iPhone应用程序进行身份验证,保留身份验证令牌和到Rails应用程序将来的请求发送沿?


使用ASIHTT prequest我想这样做像这样的:


  1. 打开一个UIWebView,从一个URL加载的我的的具体他们想要进行身份验证提供者(如myapp.com/auth/facebook为Facebook或myapp.com/ Web应用程序认证/雅虎,雅虎,等...)。


  2. 在成功,不知何故解析出与身份验证cookie中的iPhone应用程序的存储无的显示网页乡亲平时看到通过网站验证时......,而是关闭的UIWebView和导航再换另一UIVewController在iOS的应用程序。


  3. 不知怎的,包括未来的网页请求的Rails应用程序中的持久身份验证令牌。


  4. 我也希望允许用户允许iPhone应用程序在本地存储这些信息,以便他们没有,如果他们选择太,重新登录到远程应用程序。



时的这种做法合适吗?有没有更好的办法?当然,如何真正实现上述?

谢谢 - WG


解决方案

  1. 一旦的UIWebView 已经验证用的的服务,得到它加载另一个URL(例如:通过对一个javascript网页,其中的的服务返回给身份验证后)。


  2. 拍摄使用它实现了以下协议的方法 UIWebViewDelegate 对象这一要求:

       - (BOOL)web视图:(UIWebView的*)web视图shouldStartLoadWithRequest:(*的NSURLRequest)要求navigationType:(UIWebViewNavigationType)navigationType


  3. 在这里,您还可以使用的NSURLRequest 对象。您可以提取请求的标头的NSDictionary ,将使用的NSURLRequest

       - (NSDictionary的*)allHTTPHeaderFields


I am building an iOS application and I need to be able to make authenticated requests to a Rails 3 application for various bits of data. The Rails 3 application is using omniauth and URLs like https://myapp.com/auth/facebook to, for example, authenticate users via facebook ... and once authenticated, stores the authentication in a secured cookie named "auth.""

What I want to know is how to authenticate my users from the iOS/iPhone application, persist the authentication token and send it along with future requests to the Rails application?


Using ASIHTTPRequest I'm thinking of doing something like this:

  1. Open a UIWebview, loading with a URL from my web application specific for the provider they want to authenticate with (e.g. myapp.com/auth/facebook for facebook or myapp.com/auth/yahoo for yahoo, etc....).

  2. On success, somehow parse out and store the authentication cookie in the iOS application without displaying the webpage folks usually see when authenticating via the website ... and instead closing the UIWebView and navigating back to another UIVewController in the iOS application.

  3. Somehow include the persisted authentication token with future web requests to the Rails application.

  4. I also want to allow users to allow the iOS application to store this information locally so they don't have to re-login to the remote application if they choose too.


Is this approach appropriate? Is there a better way? And of course, how to actually implement the above?

Thanks - wg

解决方案

  1. Once the UIWebview has authenticated with said service, get it to load another URL (for example: through a javascript on the page which said service returns to after authentication).

  2. Capture this request using a UIWebViewDelegate object which implements the following protocol method:

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    

  3. From here you have the NSURLRequest object. You can extract the headers of the request to NSDictionary which will contain the authentication cookie details, token, etc. using the following method of NSURLRequest

    - (NSDictionary *)allHTTPHeaderFields
    

这篇关于如何到iOS / iPhone用户在相同的Web应用程序未来的请求远程Web应用程序,并重新使用身份验证票证验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆