【问题标题】:Oauth2 External Browser Request - App Launches, Credentials received, Browser Not UpdatedOauth2 外部浏览器请求 - 应用程序启动、收到凭据、浏览器未更新
【发布时间】:2013-10-29 10:29:50
【问题描述】:

我正在使用外部浏览器请求通过 OSX 中的 SoundCloudAPI 对自己进行身份验证。 我的应用程序启动,并且有一个按钮可以打开外部浏览器窗口以对 SoundCloud 进行身份验证。当我在新窗口中单击“连接”时,我得到一个与我的自定义启动 URI 方案一致的“外部协议请求”。单击此按钮会将焦点重新放在已打开的应用程序上,并获得正确的凭据。

问题是,浏览器窗口永远不会改变 - 它只是说它永远连接。没有来自 SoundCloud 的“已确认连接”警报。我知道已经过身份验证,因为我可以正确调用 API 来获取我的用户名等内容。

为什么浏览器没有确认连接或关闭?

如果我在应用程序的内部WebView 中加载身份验证,也会发生同样的事情。


也许问题是浏览器中弹出的 SoundCloud Connect 网页需要告知应用程序已连接?这是正确的思路吗?我将如何实现这一目标?


所以,我添加了一些代码来监听SCSoundCloudAccountDidChangeNotification 的变化,然后关闭窗口:

- (void)notificationReceived:(NSNotification *)aNotification;
{
    NSLog(@"%@", aNotification.name);
    SCAccount *account = [SCSoundCloud account];
    NSLog(@"%@", account.description);

    if ([SCSoundCloud account] && [aNotification.name isEqualToString:SCSoundCloudAccountDidChangeNotification]) {
        [_window close];

    }
}

在我看来,这似乎很肮脏 - 其他应用程序是这样做的吗?

【问题讨论】:

    标签: objective-c macos cocoa oauth-2.0 soundcloud


    【解决方案1】:

    您可以使用

    来捕捉请求是否完成
    -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
    

    -(void)webView:(WebView *)sender resource:(id)identifier didFinishLoadingFromDataSource:(WebDataSource *)dataSource
    

    请检查这两种方法,当请求完成时,其中一种方法应该可以工作。然后,您可以采取必要的措施,例如刷新 webview 等...

    【讨论】:

    • 我将代码更改为使用 webview,并使用第一种方法,如下所示:- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { NSString *currentURL = [[[[frame dataSource] request]URL]absoluteString]; NSLog(@"Our WebView just loaded: %@", currentURL); if ([currentURL hasPrefix:@"SCMOSX://connect"]) { NSLog(@"We're here!"); } } NSLog prints: Our WebView 刚刚加载:soundcloud.com/…` 但我从未得到第二个 "We're here"
    猜你喜欢
    • 1970-01-01
    • 2016-12-29
    • 2019-11-03
    • 2016-09-11
    • 2016-11-15
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多