我正在我的应用程序中实现 SoundCloud 登录流程。应用程序打开https://soundcloud.com/connect
in an SFSafariViewController
with a redirect_uri
它使用我的应用程序的自定义 URL 方案来接收响应。它适用于直接 SoundCloud 登录,但在尝试使用“使用 Google 登录”按钮时失败。
在 Safari 中,该按钮会打开一个带有 Google 登录页面的新选项卡(在桌面上弹出),然后通过以下方式与 SoundCloud 选项卡进行通信:postMessage
。如果您使用 iOS Safari 应用程序,此登录流程可以正常工作,但会失败SFSafariViewController
(单击按钮会转到带有 Google 网址的白页:https://accounts.google.com/o/oauth2/auth?...
).
目前我的解决方法是建议使用 Google 的用户点击 Safari 图标SFSafariViewController
完成 Safari 应用程序中的登录流程,但我想知道是否有一种方法可以在不离开我的应用程序的情况下处理此问题。
好吧,如果我使用UIWebView
,您可以在用户通过 Google 进行身份验证后从 google 获取最终的 oauth 响应。然而,我们如何将其转回到 SoundCloud(例如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 );
}
}
Output:
{
"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 登录步骤的 URL 如下 - 为了方便起见,我已经解码了下面的 URL 转义编码:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)