简体   繁体   中英

Authentication issues with Azure Mobile Service for Windows Phone

I am attempting authentication with Google using Azure Mobile Service's Authentication Providers. I have followed the tutorial in the documentation ( http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-phone-get-started-users/ ) and have applied it to my app's login screen. It does show a login prompt for Google, and I enter credentials and click sign in. Then instead of asking for consent to use my account details like expected, it goes back to my app's login screen.

I'm not sure what's wrong, or how to figure out what's wrong. I am somewhat new to Windows Phone development, and development in Visual Studio at all, being more used to Android development and Eclipse. This is new to me, and I'm lost.

Here's the code I use for Google authentication.

private async System.Threading.Tasks.Task aaGoogle()
{
    while (user == null)
    {
        string message;
        try
        {
            user = await App.MobileService
                .LoginAsync(MobileServiceAuthenticationProvider.Google);
            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();
    }
}

Ah, Microsoft's documentation is incomplete. I'm using a .NET backend and C# for my app, and the default callback URLs are made for the Javascript backend. So the correct callback URLs for the .NET backend are:

  • [mobileservice].azure-mobile.net/signin-twitter
  • [mobileservice].azure-mobile.net/signin-facebook
  • [mobileservice].azure-mobile.net/signin-google
  • [mobileservice].azure-mobile.net/signin-microsoft

After changing the links to those for all of the relevant services, the login screens and consent screens worked perfectly, and I got the login details for each account. Everything works as intended. I hope this helps someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM