无法登录azure移动服务:"请求无法完成。 (未授权)

时间:2014-12-15 20:01:22

标签: authentication azure azure-mobile-services windows-live

我正在使用.Net后端开发移动服务,但无法将我的应用程序签入新服务。我能够在本地以调试模式运行Web应用程序,但是当我尝试在实时服务上验证应用程序时,我失败了。到目前为止,我已经完成了以下工作:

在WebApiConfig.cs文件中,我添加了:

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

在实时应用程序配置中,我有以下摘要:

Live application configuration

然后当我创建MobileServiceClient时,我使用:

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

要登录Windows Live,我使用此功能在用户控件中托管的内置控件:

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);
        }
    }

在登录助手中,我有这个:

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 个答案:

没有答案