我编写了一个基于 XAML 的 WinRT 应用程序,它通过 WebAuthenticationBroker.AuthenticateAsync 调用连接到 foursquare。这是授权码:
public async Task<string> FsqAuthenticate()
{
var fsqAuthUrl = string.Format(
"https://foursquare.com/oauth2/authenticate?client_id={0}&response_type=code&redirect_uri={1}&display=webpopup",
ClientId, RedirectUri);
var requestUri = new Uri(fsqAuthUrl, UriKind.RelativeOrAbsolute);
var redirUri = new Uri(RedirectUri, UriKind.RelativeOrAbsolute);
string authCode = string.Empty;
string authToken = string.Empty;
try
{
ResponseErrorMsg = string.Empty;
WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.None,
requestUri, redirUri);
if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
如果用户选择直接通过 foursquare 进行身份验证,或通过 foursquare 注册,则效果很好。然而,foursquare OAuth 页面为用户提供了通过 Facebook 登录/注册的选项。如果选择,初始 Facebook 登录屏幕将正确显示;用户可以输入用户名/密码并选择“登录”按钮;然后窗口一片空白。看来控制权正在被传递给 Facebook 的弹出窗口,提示授予权限。但是,WebAuthenticationBroker 没有显示此内容。出于所有意图和目的,WebAuthenticationBroker 已挂起。
是否存在针对此行为的解决方法?
最佳答案
我终于得到了微软关于这个问题的回复:
Facebook Connect won’t work as it requires communication between multiple pages but the Webauth Broker can only have one active at a time. The issue here is that foursquare launches a popup for facebook authorization and waits for the popup to complete and an event to fire on the first foursquare page. In the case of webauth, we navigate to all popups inline, so the first page that launches the popup will be gone and there is no event that can be sent back to the first page.
结果是,除了编写自己的登录过程并完全绕过 WebAuthenticationBroker(我最终这样做)之外,没有解决方法。
TL;DR:WebAuthenticationBroker 已损坏,目前没有计划修复它。
关于windows-8 - 如果从 foursquare 传递到 Facebook,WebAuthenticationBroker 将挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12388221/