title: azure mobile services authentication
body: <p>I am developing an application for Windows Phone 8. I am trying to implement authentication using this very simple example here: <a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-wp8/" rel="nofollow">http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-wp8/</a>, followed by this one here: <a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-wp8/" rel="nofollow">http://www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-wp8/</a>. It is essential for my application to continue to be able authenticate and control access of the users of my application. Specifically my problem is here: </p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>This is about as much code as there is for both tutorials. It starts the login screen at <code>user = await App.MobileService
                          .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);</code>
  but after accepting the login credentials, it starts displaying the error message which is:</p>
  
  <pre><code>+       $exception  {System.InvalidOperationException: Cannot start a login operation because login is already in progress.
  
  at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.&lt;SendLoginAsync&gt;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.&lt;Authenticate&gt;d__7.MoveNext()}   System.Exception {System.InvalidOperationException}
  </code></pre>
  
  <p>It repeats this process because "user" never gets assigned, due to the "login is already in progress" situation. I cant find anything online to help, I have searched for this error and only get 4 hits of the exact problem which are bits of github code and no help as far as I can see.</p>