AADSTS50011:请求中指定的回复URL与应用程序配置的回复URL不匹配: '

3

我创建了一个API应用并将其部署到Azure。该应用程序使用Active Directory身份验证。
我收到以下错误信息:

AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application: 00000000-0000-4f27-0000-00000000.

目前为止的步骤

  • 启用了Active Directory身份验证
  • 设置CORS为*
  • 将回复URL设置为相同地址https://myapp.azurewebsites.net/
  • 我已在web config中添加了以下设置

config

  <add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}"></add>
    <add key="ida:PostLogoutRedirectUri" value="https://myapp.azurewebsites.net/"></add>

这个API的代码如下:

[HttpGet]
        [SwaggerResponse(HttpStatusCode.OK,
            Type = typeof(IEnumerable<Contact>))]
        public async Task<IEnumerable<Contact>> Get()
        {
            return await GetContacts();
        }
5个回答

0

我在按照微软教程从 Windows 桌面应用程序调用 Microsoft Graph API时遇到了同样的问题。在我的代码中没有任何地方提供重定向 URL,除了这一行:

.WithDefaultRedirectUri();

当我将鼠标悬停在上面时,我发现它是https://login.microsoftonline.com/common/oauth2/nativeclient,这是我的Azure应用程序上存在的重定向URI。这一切都非常令人困惑,我在网上找不到答案。经过大约3个小时的搜索答案和尝试代码中的许多可能性后,我在我下载的文件中找到了这个注释:
// Requires redirect URI "ms-appx-web://microsoft.aad.brokerplugin/{client_id}" in app registration

所以我去了https://ms.portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Authentication/appId/171axxxx-xxxx-xxxx-xxxx-xxxxxxxxafff/isMSAApp/,在身份验证和gt;重定向URI下添加了重定向URI ms-appx-web://microsoft.aad.brokerplugin/171axxxx-xxxx-xxxx-xxxx-xxxxxxxxafff。

接下来,我修改了我的代码,像这样:

public partial class App : Application
    {
        // Below are the clientId (Application Id) of your app registration and the tenant information. 
        // You have to replace:
        // - the content of ClientID with the Application Id for your app registration
        // - The content of Tenant by the information about the accounts allowed to sign-in in your application:
        //   - For Work or School account in your org, use your tenant ID, or domain
        //   - for any Work or School accounts, use organizations
        //   - for any Work or School accounts, or Microsoft personal account, use common
        //   - for Microsoft Personal account, use consumers
        private static string ClientId = "171axxxx-xxxx-xxxx-xxxx-xxxxxxxxafff";

        // Note: Tenant is important for the quickstart.
        private static string Tenant = "72f9xxxx-xxxx-xxxx-xxxx-xxxxxxxxdb47"; //also works with "common"
        private static string Instance = "https://login.microsoftonline.com/";
        private static IPublicClientApplication _clientApp;


        static App()
        {
            CreateApplication(true);
        }


        public static void CreateApplication(bool useWam)
        {
            //initialize MSAL
            var builder = PublicClientApplicationBuilder.Create(ClientId)
                .WithAuthority($"{Instance}{Tenant}")
                .WithDefaultRedirectUri();

            if (useWam)
            {
                builder.WithExperimentalFeatures();
                builder.WithBroker(true);  // Requires redirect URI "ms-appx-web://microsoft.aad.brokerplugin/{client_id}" in app registration
            }
            _clientApp = builder.Build();
            TokenCacheHelper.EnableSerialization(_clientApp.UserTokenCache);
        }

        

        public static IPublicClientApplication PublicClientApp { get { return _clientApp; } }
    }

我不知道为什么Azure没有将这个重定向与其他重定向一起添加,因为他们知道这是必要的,或者至少在说明中包含这个步骤,但希望这对其他遇到此错误的人有所帮助。


0

获取 Fiddler 跟踪,查看在您尝试对应用程序进行身份验证时通过浏览器传输的内容。应该会有一个请求发送到 AAD 请求身份验证,其中还包括一个回复 URL。请确保它与您在 AAD 中配置的应用程序相同。


0
你在web.config文件中设置了以下键和值吗? key="ida:RedirectUri" value="https://myapp.azurewebsites.net/"

0

0

遇到了相同的错误,解决方法如下:

前往 Azure 门户:https://portal.azure.com 登录并单击左侧的 Azure Active Directory 图标。然后在中间窗格中单击“应用程序注册”图标。在搜索框中输入出现错误消息的应用程序,并从下拉列表中选择“所有应用程序”:

单击您的应用程序,然后单击设置图标,从列表中选择“回复 URL”。

复制其中一个回复 URL 并将其添加为您的应用程序的 https 端口。

您可以从项目属性中执行此操作,或者只需在 lounchsetting.json 文件中添加 sslPort 值即可。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接