asp.net-core - 如何在 .Net Core 3.1 中的 OpenId 连接时禁用 ssl 证书验证?

标签 asp.net-core ssl certificate openid openid-connect

我正在尝试在开发环境中使用其 ip 地址连接到开放 id 授权。显然,在这种情况下,ssl 验证将失败。我想绕过它,到目前为止没有任何运气。我找到了有关此主题的以下答案:

  • 在 OpenIdConnectOptions 类中将 RequireHttpsMetadata 设置为 false。
  • 使用以下代码:

  • ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;


    当我的应用程序尝试访问 oidc 权限时,我收到相同的错误:

    An unhandled exception occurred while processing the request. AuthenticationException: The remote certificate is invalid according to the validation procedure. System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)

    HttpRequestException: The SSL connection could not be established, see inner exception. System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)

    IOException: IDX20804: Unable to retrieve document from: 'https://172.11.0.11:1111/MY_APP/.well-known/openid-configuration'. Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel)

    InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://172.11.0.11:1111/MY_APP/.well-known/openid-configuration'. Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken cancel)

    最佳答案

    警告:仅在开发过程中使用它。如果合适,您需要为您的生产平台定制证书验证例程。
    您可能覆盖了错误的 HttpClientHandler。 OpenId Connect 的反向 channel HttpClient 可以在此处被覆盖:

    services
        .AddAuthentication(options =>
        {
            ...
        })
        .AddCookie()
        .AddOpenIdConnect(options =>
        {
            ...
            HttpClientHandler handler = new HttpClientHandler();
            handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            options.BackchannelHttpHandler = handler;
        });
    

    关于asp.net-core - 如何在 .Net Core 3.1 中的 OpenId 连接时禁用 ssl 证书验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62990470/

    相关文章:

    c# - 如何在 .NET Core 中创建动画 gif

    c# - 尝试在 VS 2017 中的 ASP.NET Core 中构建项目时出现 UseBrowserLink 错误

    java - 为什么 SSL 服务器套接字连接会在 Java 中阻塞,而非 SSL 服务器套接字不会?

    html - SSL 加密页面中的 HTTP iframe

    java - 如何在JAVA中计算证书的公钥与Windows计算的公钥相匹配

    ssl - 可以在没有 CSR 和使用旧私钥的情况下颁发证书吗

    sql-server - Entity Framework 核心在 c# 中将 float(db 数据类型)转换为 double 时添加数字

    ios - 从 "SecTrustCopyPublicKey"调用收到的值的含义

    iOS mobileconfig 解决方法

    unit-testing - 将 asp.net 5 测试放在单独的程序集中