.Net バックエンドを使用してモバイル サービスを開発していますが、新しいサービスにアプリをサインインできません。Web アプリケーションをローカルでデバッグ モードで実行できますが、ライブ サービスでアプリを認証しようとすると失敗します。これまでのところ、次のことを行いました。
WebApiConfig.cs ファイルに、次を追加しました。
options.LoginProviders.Remove(typeof (AzureActiveDirectoryLoginAuthenticationProvider));
options.LoginProviders.Add(typeof (AzureActiveDirectoryExtendedLoginProvider));
ライブ アプリケーションの構成には、次の概要があります。
次に、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;
}