处理SFSafariViewController中的弹出窗口/选项卡 [英] Handle popups/tabs in SFSafariViewController

查看:288
本文介绍了处理SFSafariViewController中的弹出窗口/选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中实现SoundCloud登录流程.该应用程序使用redirect_uriSFSafariViewController中打开https://soundcloud.com/connect,该redirect_uri使用我的应用程序的自定义URL方案来接收响应.对于直接的SoundCloud登录,它可以正常工作,但是在尝试使用其使用Google登录"按钮时失败.

I'm implementing a SoundCloud login flow in my app. The app opens https://soundcloud.com/connect in an SFSafariViewController with a redirect_uri that uses my app's custom URL scheme to receive the response. It works fine for direct SoundCloud logins, but fails when trying to use their "Sign in with Google" button.

在Safari中,该按钮会打开一个带有Google登录页面的新标签页(在桌面上弹出),然后通过postMessage通讯回SoundCloud标签页.如果您使用iOS Safari应用程序,则此登录流程可以正常运行,但在SFSafariViewController失败(单击该按钮将转到带有Google url的白页:https://accounts.google.com/o/oauth2/auth?...).

In Safari, that button opens a new tab (popup on desktop) with a Google sign-in page, which then communicates back to the SoundCloud tab via postMessage. This login flow works fine if you use the iOS Safari app, but fails in an SFSafariViewController (clicking the button goes to a white page with a Google url: https://accounts.google.com/o/oauth2/auth?...).

现在,我的解决方法是建议使用Google的用户点击SFSafariViewController上的Safari图标以完成Safari应用程序中的登录流程,但是我想知道是否有一种方法可以在不离开我的应用程序的情况下进行处理.

Right now my workaround is to advise users using Google to tap the Safari icon on the SFSafariViewController to complete the login flow in the Safari app, but I'm wondering if there's a way to handle this without leaving my app.

推荐答案

好吧,如果我使用UIWebView,则在用户向Google进行身份验证后,您可以从Google获取最终的oauth响应.但是,我们如何将其转回SoundCloud(例如soundcloud.com/connect/via/google_plus/returning)

Well, if I use a UIWebView, you can grab the final oauth response from google after the user authenticates with Google. However, how do we turn that back around to SoundCloud (e.g. soundcloud.com/connect/via/google_plus/returning)

- (void) webViewDidFinishLoad:(UIWebView*)inWebView {

    NSString* str = [inWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('response-form-encoded').value"];
    if ( str.length > 0 ) {
        NSDictionary* params = parseURLParams( str );
        NSLog( @"%@", params );
    }
}

输出:

{
    "access_token" = "ya2...<removed>...4g";
    authuser = 0;
    code = "4/sU_g7....<removed>...fnRELA";
    "expires_in" = 3600;
    "id_token" = "eyJhb...<removed>...DA";
    prompt = none;
    scope = "https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/plus.login+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/plus.moments.write+https://www.googleapis.com/auth/plus.me+https://www.googleapis.com/auth/plus.profile.agerange.read+https://www.googleapis.com/auth/plus.profile.language.read+https://www.googleapis.com/auth/plus.circles.members.read";
    "session_state" = "c8703a085b885bbe8c8d0e29277b0c2fdf9c6c87..65aa";
    state = "392921654%7C0.288515904";
    "token_type" = Bearer;
}

启动Google登录步骤的网址如下-为方便起见,我对以下网址转义编码进行了解码:

The URL that initiates the google login step is below -- I've decoded the URL escape encoding below for convenience:

    https://accounts.google.com/o/oauth2/auth?client_id=984739005367.apps.googleusercontent.com&response_type=code token id_token gsession&scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.profile&state=425511939|0.2912748339&access_type=offline&request_visible_actions=http://schemas.google.com/AddActivity http://schemas.google.com/ListenActivity http://schemas.google.com/CreateActivity&after_redirect=keep_open&cookie_policy=single_host_origin&prompt=none&include_granted_scopes=true&proxy=oauth2relay751149297&redirect_uri=postmessage&origin=https://soundcloud.com&gsiwebsdk=1&authuser=0&jsh=m;/_/scs/apps-static/_/js/k=oz.gapi.en.TA32fes-0yU.O/m=__features__/am=AQ/rt=j/d=1/rs=AGLTcCOuWXPCbMjoOmrZx_gBsAG8J20NLA

这篇关于处理SFSafariViewController中的弹出窗口/选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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