Question

I'm starting with Azure Mobile Service and authentication with all the providers works great except Google.

I have created Client ID for web apps: https://db.tt/s43Gi7ie

Then configured it at the Windows Azure Mobile Service panel: https://db.tt/ri3VzYFD

Then I created new Windows Phone 8 app, add Azure Mobile Services nuget package and wrote several lines of code:

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

                MessageBox.Show(message);
            }
        }

But every time I'm calling the AuthenticateGoogle method I received 400 error.

System.InvalidOperationException: Authentication failed with HTTP response code 400.
   at Microsoft.WindowsAzure.MobileServices.AuthenticationBroker.<AuthenticateAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- 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.TaskAwaiter`1.GetResult()
   at Microsoft.WindowsAzure.MobileServices.MobileServiceAuthentication.<LoginAsync>d__0.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.TaskAwaiter`1.GetResult()
   at PhoneApp1.SSOPage.<AuthenticateGoogle>d__19.MoveNext()

What am I doing wrong?

Was it helpful?

Solution

It looks good to me. I did basically the same steps as the tutorial you followed. I was having trouble with Google so I just went to the Google Developers Console, created a new Client ID, and then replaced the new keys with the old. I also included the same URL but as a http:// instead of an https://, but after I saw that it started working again I took the http:// out and it still works.

Other than that make sure everything is spelled correctly and good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top