Azure移动服务身份验证

3
我正在开发一个针对Windows Phone 8的应用程序。我尝试使用这个非常简单的例子来实现身份验证: http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-wp8/,然后是这个: http://www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-wp8/。对于我的应用程序来说,继续能够认证和控制用户访问是至关重要的。具体地,我的问题在这里:

private async System.Threading.Tasks.Task Authenticate()
{
    while (user == null)
    {
        string message;
        try
        {
            user = await App.MobileService
                        .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
            message = string.Format("You are now logged in - {0}", user.UserId);
        }
        catch (InvalidOperationException e)
        {
            message = e + "You must log in. Login Required";
        }
        MessageBox.Show(message);
    }
}

以下是两个教程中几乎所有的代码,它从 user = await App.MobileService .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount); 开始登录界面。但在接受登录凭据后,开始显示错误消息,该消息为:

+       $exception  {System.InvalidOperationException: Cannot start a login operation because login is already in progress.

at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.<SendLoginAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at SeeThrough.MainPage.<Authenticate>d__7.MoveNext()}   System.Exception {System.InvalidOperationException}

它会重复这个过程,因为“user”从未被分配,原因是“登录已在进行中”。我找不到任何在线帮助,我已经搜索了这个错误,只得到了4个精确的问题,它们是github代码的一部分,据我所见没有任何帮助。
2个回答

0

虽然这是一个老问题,但它对我很有帮助。

引用来自MSDN论坛的答案

我忘了提到,我们的教程还没有更新到Windows Phone 8.1,所以您还需要将以下代码添加到app.xaml.cs中(此片段适用于通用应用程序,电话8.1也是一样的,只是不需要条件)

protected override void OnActivated (IActivatedEventArgs args)
{
    base.OnActivated (args);

#if WINDOWS_PHONE_APP
    if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
        App.<mobileservice>.LoginComplete (args as WebAuthenticationBrokerContinuationEventArgs);
#endif
}

0

我觉得你没有正确配置账户。请在实时仪表板的应用注册页面上提供正确的移动服务URL。如果URL不正确,很可能会出现这样的异常!


重定向URL在Live Connect开发者中心与Azure管理门户中显示的移动服务URL相同。客户端ID和客户端密钥也在两者中都是相同的。客户端ID是否必须在应用程序本身中某个位置?也许这是我大学最终项目的问题,如果不尽快解决,我将会失败。 - john

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接