0
votes

WAMS: Microsoft authentication.

http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-store-dotnet-get-started-users/

Changed from Facebook to MicrosoftAccount

PROBLEM: When I click on the back arrow (to escape the login) It should still be in the while loop and force another popup never allowing the user to have success. Instead it hit the

catch (InvalidOperationException)


private MobileServiceUser user;
private async System.Threading.Tasks.Task AuthenticateAsync()
{
   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)
       {
           message = "You must log in. Login Required";
       }

       var dialog = new MessageDialog(message);
       dialog.Commands.Add(new UICommand("OK"));
       await dialog.ShowAsync();
    }
}
1
Well, if I remove any breakpoints it "works" , I suppose it hitting the catch (InvalidOperationException) is fine?Tom Stickel

1 Answers

1
votes

When you cancel the authentication page, the awaited call to LoginAsync will throw the InvalidOperationException. That's expected - you asked the SDK to login, the login operation didn't succeed, so you get an exception. When the exception is thrown, the assignment to the user field doesn't happen, so it retains its original value (null), which is why the loop continues. If you have a breakpoint in the catch block, and continue after hitting the breakpoint (F5), it should prompt with the authentication again.