我最近在try 使用twitter登录时出现了这个错误——知道为什么吗?

Stack Trace: 


[AuthenticationException: The remote certificate is invalid according to the validation procedure.]
   System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) +230
   System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) +13
   System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) +123

[WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.]
   System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +6432446
   System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +64

推荐答案

多亏了开源的力量,我们可以看到Twitter证书的 fingerprint 已经编码到了Katana项目中.

Microsoft.Owin.Security.Twitter.TwitterAuthenticationOptions

最近一些证书肯定已经更改,现在 fingerprint 不再匹配.

请将"VeriSign Class 3 Public Primary Certification Authority-G5"证书的新 fingerprint 添加到您Startup.Auth.cs(MVC用户)的Twitter认证选项中.

更改默认设置:

app.UseTwitterAuthentication(
    consumerKey: "XXXX",
    consumerSecret: "XXX"
);

使用这个:

app.UseTwitterAuthentication(new TwitterAuthenticationOptions
{
    ConsumerKey = "XXXX",
    ConsumerSecret = "XXXX",
    BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(new[]
    {
        "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2
        "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3
        "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5
        "39A55D933676616E73A761DFA16A7E59CDE66FAD", // Symantec Class 3 Secure Server CA - G4
        "5168FF90AF0207753CCCD9656462A212B859723B", //DigiCert SHA2 High Assurance Server C‎A 
        "B13EC36903F8BF4701D498261A0802EF63642BC3" //DigiCert High Assurance EV Root CA
    })
});

.net相关问答推荐

使用React路由加载器获取数据不能正常工作

如何在 .net MAUI 中删除不需要编译的平台?

仅在有换行符时捕获分隔符之间的所有文本

当 Func 委托需要接口作为参数时,它是如何工作的?

.NET 的future 版本会支持 C# 中的元组吗?

指定的版本字符串不符合要求的格式 - major[.minor[.build[.revision]]]

使用泛型装箱和拆箱

File.ReadAllLines() 和 File.ReadAllText() 有什么区别?

基于多个字符分隔符拆分字符串

寻找 .NET 的命令行参数解析器

String.Format - 它是如何工作的以及如何实现自定义格式字符串

SQLParameter 如何防止 SQL 注入?

我不了解应用程序域

使用 XmlSerializer 将空 xml 属性值反序列化为可为空的 int 属性

在 C# 中,为什么不能将 List 对象存储在 List 变量中

什么是 .NET 应用程序域?

Guid.Parse() 或 new Guid() - 有什么区别?

使用 DateTime.ToString() 时获取日期后缀

MemoryCache 不遵守配置中的内存限制

是 C# 中的 bool 读/写原子