azure移动服务认证

时间:2013-03-19 19:56:05

标签: azure windows-phone-8

我正在为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}

它重复此过程,因为“登录已在进行中”状态,“用户”永远不会被分配。我无法在网上找到任何帮助,我已经搜索了这个错误,并且只得到了4个确切问题的点击,这些是github代码并且我认为没有任何帮助。

2 个答案:

答案 0 :(得分:0)

我认为您尚未正确配置帐户。请在实时仪表板的应用程序注册页面中提供正确的移动服务URL。如果网址不对,则更有可能获得此类例外!

答案 1 :(得分:0)

老问题,但这有助于我。

MSDN Forums

引用回答
  

我忘了提及,我们的教程尚未针对窗口进行更新   手机8.1,所以你还需要添加以下代码   进入你的app.xaml.cs(这个代码片段适用于univeral app,phone 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
}