Asp.net web api Azure Active Directory许可框架未启动.NET客户端应用程序

Asp.net web api Azure Active Directory许可框架未启动.NET客户端应用程序,asp.net-web-api,azure-active-directory,Asp.net Web Api,Azure Active Directory,我有一个运行在Azure Web应用程序中的Web API。它从.NET WinForms客户端应用程序中使用。在同一个Azure Web应用程序中,还有一个ASP.NET MVC站点 用户使用Azure AD凭据对站点和.NET客户端进行身份验证。这应该是多租户的。MVC应用程序在多租户环境下运行良好,但我无法让客户端运行多租户环境 我的理解是,如果使用OAuth 2.0,同意框架应该自动启动。我正在使用的代码(如下)非常接近于目前的示例 虽然我可以与定义了本机应用程序的租户中的用户成功登录并

我有一个运行在Azure Web应用程序中的Web API。它从.NET WinForms客户端应用程序中使用。在同一个Azure Web应用程序中,还有一个ASP.NET MVC站点

用户使用Azure AD凭据对站点和.NET客户端进行身份验证。这应该是多租户的。MVC应用程序在多租户环境下运行良好,但我无法让客户端运行多租户环境

我的理解是,如果使用OAuth 2.0,同意框架应该自动启动。我正在使用的代码(如下)非常接近于目前的示例

虽然我可以与定义了本机应用程序的租户中的用户成功登录并使用该应用程序,但我无法与其他租户的用户一起使用该应用程序。没有征得同意,我有一个AdalException:

AADSTS50001: The application named https://<myurl> was not found in the tenant named <sometenant>.onmicrosoft.com.  This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant.  You might have sent your authentication request to the wrong tenant.
Trace ID: 3<snip>2
Correlation ID: 2<snip>a
Timestamp: 2017-01-05 01:01:10Z

谢谢你的洞察力

我试图重现这个问题,但失败了。当我使用多租户帐户登录本机应用程序时,本机客户端应用程序使用Azure保护的web API的场景效果良好。我从中测试了代码示例


根据错误消息,似乎资源不正确,请确保它与您在Azure上注册的web API应用的应用ID URI相同。当我指定了一个不正确的资源时,我可能会收到相同的错误消息

如果有不正确的资源,它肯定不会与任何租户中的帐户一起工作?它与定义本机客户端应用程序的租户的帐户一起工作。
Uri RedirectUri = new Uri(sRedirectUri);
// AadInstance is the common tenant
AuthenticationContext authContext = new AuthenticationContext(AadInstance);

try
{
    PlatformParameters pp = new PlatformParameters(PromptBehavior.Auto);
    // Authenticate to Azure AD
    Program.WebApiAuthenticationResult = await authContext.AcquireTokenAsync(WebAppIdUri, ClientID, RedirectUri, pp);
    return true;
}
catch (AdalException ex)
{
    MessageBox.Show(ex.Message, "Log In Not Successful");
}