not able to log in to azure mobile service: "Request could not be completed. (Unauthorized)

361 views Asked by At

I am developing a mobile service with a .Net backend and am not able to sign my app in to the new service. I am able to run the web application in debug mode locally, but I fail when I try to authenticate the app on the live service. So far, I've done the following:

In the WebApiConfig.cs file, I added:

options.LoginProviders.Remove(typeof (AzureActiveDirectoryLoginAuthenticationProvider));
options.LoginProviders.Add(typeof (AzureActiveDirectoryExtendedLoginProvider));

In the Live application configuration, I have this summary:

Live application configuration

Then when I create the MobileServiceClient, I use:

public const string AppUrl = @"https://japanesehub.azure-mobile.net/";
public const string ClientSecret = "***************************";

For logging in to Windows Live, I use the built in control hosted in a user control with this function:

private async void SignInButton_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
    {
        if (e.Status == Microsoft.Live.LiveConnectSessionStatus.Connected) // this passes
        {
            App app = App.Current as App;
            if (e.Status == LiveConnectSessionStatus.Connected)
            {
                SignInButton.Visibility = Visibility.Collapsed;

                await new LoginHelper().LoginToAzure(App.MobileService, e.Session);
            }
            else
            {
                //infoTextBlock.Text = "Not signed in.";
                app.AzureManager.Client = null;
            }
            if (LoginCompleted != null)
                LoginCompleted(this, e);
        }
    }

and in the login helper, I have this:

public async Task<bool> LoginToAzure(MobileServiceClient client, LiveConnectSession session)
    {
        bool success = true;
        try
        {
            // now, login to azure
            client.CurrentUser = await client.LoginWithMicrosoftAccountAsync(
                    session.AuthenticationToken);
            AzureManager.Manager.User = client.CurrentUser;
        }
        catch (Exception ex)
        {
            success = false;
            Debug.WriteLine("Failed to log in to Azure: " +ex.Message);
            // message is The request could not be completed.  (Unauthorized)
        }
        return success;
    }
0

There are 0 answers