更新:这似乎只发生在我在模拟器中运行应用程序时。当我在真实设备上运行它时,一切都按预期工作。
我在我的应用程序中使用WebAuthenticationBroker让用户通过 OAuth 向 Fitbit 进行身份验证。
WebAuthenticationBroker 成功地将 args 传回给我(即包含令牌和秘密的最终 URI),我能够进行后续调用以从 Fitbit 检索访问令牌。所有这些都按预期工作。
我的问题是该应用程序然后挂在“正在恢复...”行军蚂蚁屏幕上。这发生在 WebAuthenticationBroker Fitbit 登录屏幕消失后,并且与我之后执行的任何代码无关。我已经删除了所有这些代码,它仍然会发生。
我用来启动 WebAuthenticationBroker 的调用是
string CallBackUrl = "http://localhost:8080/Fitbit/Callback";
string oauth_token = await GetFitbitRequestTokenAsync(CallBackUrl, ConsumerKey);
string FitbitUrl = "https://www.fitbit.com/oauth/authorize?oauth_token=" + oauth_token;
System.Uri StartUri = new Uri(FitbitUrl);
System.Uri EndUri = new Uri(CallBackUrl);
WebAuthenticationBroker.AuthenticateAndContinue(StartUri, EndUri, null, WebAuthenticationOptions.None);
我假设在所有这些之后我错过了一个步骤,这是返回我的应用程序页面所必需的。我已经尝试了各种我能想到的东西,但我不确定我需要在哪里以及如何做到这一点才能让它发挥作用。
我从 WebAuthenticationManager 获取带有令牌/秘密参数的 CallbackUrl 的方式是
protected async override void OnActivated(IActivatedEventArgs e)
{
base.OnActivated(e);
var args = e as IContinuationActivatedEventArgs;
if (args != null && args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
Frame rootFrame = Window.Current.Content as Frame;
var wabPage = rootFrame.Content as IWebAuthenticationContinuable;
wabPage.ContinueWebAuthentication(args as WebAuthenticationBrokerContinuationEventArgs);
}
Window.Current.Activate();
}
非常感谢您的帮助!:)
_ 求和