IDX10803:无法创建从以下位置获取配置:“https://login.microsoftonline.com/{Tenant-ID}/.well-known/openid-configuration”

Ale*_*lex 6 azure azure-active-directory openid-connect

在过去的 5 年里,我一直在使用 Azure IoT 远程监控解决方案并使用 Azure AD 身份验证来保护应用程序和 API,从上周六开始,我在登录时收到以下错误(黄色屏幕):

IDX10803:无法创建从“https://login.microsoftonline.com/{Tenant-ID}/.well-known/openid-configuration”获取配置。

这是我的身份验证相关的启动代码:

public void ConfigureAuth(IAppBuilder app, IConfigurationProvider configProvider)
    {
        string aadClientId = configProvider.GetConfigurationSettingValue("ida.AADClientId");
        string aadInstance = configProvider.GetConfigurationSettingValue("ida.AADInstance");
        string aadTenant = configProvider.GetConfigurationSettingValue("ida.AADTenant");
        string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, aadTenant);

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());


        app.UseWindowsAzureActiveDirectoryBearerAuthentication(
            new WindowsAzureActiveDirectoryBearerAuthenticationOptions
            {
                Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
                TokenValidationParameters = new TokenValidationParameters { SaveSigninToken = true, ValidAudience = ConfigurationManager.AppSettings["ida:Audience"] }
            });


        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = aadClientId,
                Authority = authority,
                TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer = false
                },
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    RedirectToIdentityProvider = (context) =>
                    {
                        string appBaseUrl = context.Request.Uri.Scheme + "://" + context.Request.Uri.Authority + "/";
                        context.ProtocolMessage.RedirectUri = appBaseUrl;
                        context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
                        return Task.FromResult(0);
                    },
                    AuthenticationFailed = context =>
                    {
                        string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;

                        context.ProtocolMessage.RedirectUri = appBaseUrl + "/";
                        context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
                        context.HandleResponse();
                        context.Response.Redirect(context.ProtocolMessage.RedirectUri);

                        return Task.FromResult(0);
                    }
                }
            });
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用 azure 应用程序服务来托管我的 Web 应用程序,它是基于 .NET Framework 4.6 构建的。我将 Web 应用程序的最低 TLS 版本从 1.0 更改为 1.2。

我可以看到很多与此相关的问题,但找不到正确的答案,这就是我发布此内容的原因。如果需要更多信息我可以提供。谢谢

编辑:我的 Web 应用程序没有 SSL 证书,由于某些原因我们无法使用它。

Bre*_*ner 20

解决了我的问题。我找到了两种方法。

就我而言,OWIN 包在加载元数据时默认使用 TLS 1.1。显然他们现在正在全面弃用这些 SSL 证书,因此周末就会出现损坏。这两种方法都会强制 OpenConnect 进程中发生的任何调用使用 TLS 1.2 或更高版本,并允许获取 openid 配置。

选项1

您可以在 Global.asax.cs 中添加以下内容:

using System.Net;
.
.
protected void Application_Start()
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; // only allow TLSV1.2 and SSL3

    //The rest of your startup code goes here
}
Run Code Online (Sandbox Code Playgroud)

选项2

还有另一种使用 web.config 的方法,不涉及代码更改。如果 .NET 4.7.2 可用(位于 Azure 上),您可以添加以下内容:

<system.web>
  <httpRuntime targetFramework="4.7.2" />
</system.web>
Run Code Online (Sandbox Code Playgroud)

如果使用 4.7.2 运行时会导致应用程序发生重大更改,则这可能不起作用。它不需要更新编译版本,并且在我测试的场景中它没有引起任何问题。