Azure AD経由でAzure Mobileサービス(.NETバックエンド)を認証するのに苦労しています。
私はこのチュートリアルに従いました:https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-how-to-configure-active-directory-authentication/
Azure AD自体への認証は成功しましたが(result.Status == AuthenticationStatus.Success
)、MobileService.LoginAsyncでHTTP 401を取得します。UWPクライアントからAzure Mobileサービスで認証します。
モバイルサービスのAzure ADアプリの設定
サインオンURL:https://contososervice.azurewebsites.net
クライアントID:c710fe9b-4dd2-406b-ae68-ea5825c2c103
のApp ID URI:https://contososervice.azurewebsites.net
返信URL:https://contososervice.azurewebsites.net/.auth/login/aad/callback
ネイティブクライアントAzure AD appの設定
クライアントID:d79fea3f-2357-4797-9be8-48d630f6e1a3
リダイレクトのURI:
- https://contososervice.azurewebsites.net/.auth/login/done
- MS-アプリ:// S-1-15-2-4177921760-2458829842-3328621796-4043898254-238447652-453539330-2174227773
ContosoService
アズールに委任許可モバイルサービスの認証の設定:詳細設定モード
クライアントID:c710fe9b-4dd2-406b-ae68-ea5825c2c103
発行元URL:https://sts.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47
モバイルサービスweb.conf
<add key="ida:Tenant" value="contoso.onmicrosoft.com" /> <add key="ida:Audience" value="https://contososervice.azurewebsites.net" />
IGモバイルサービス認証設定
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
},
});
}
UWPクライアント
string appIDUri = "https://contososervice.azurewebsites.net";
string clientID = "d79fea3f-2357-4797-9be8-48d630f6e1a3";
AuthenticationResult result = await _authContext.AcquireTokenAsync(
appIDUri,
clientID,
WebAuthenticationBroker.GetCurrentApplicationCallbackUri());
if (result.Status == AuthenticationStatus.Success)
{
IsUserAuthenticated = true;
UserData = result.UserInfo;
success = true;
JObject payload = new JObject();
payload.Add("access_token", result.AccessToken);
var user = await ServiceClient.ServiceClient.MobileService.LoginAsync(
MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
payload);
}