LinkedIn 授权代码流(三足 OAuth)- 现有连接被远程主机强行关闭

LinkedIn Authorization Code Flow (3-legged OAuth) - An existing connection was forcibly closed by the remote host

我们有一个 ASP.NET (4.6) MVC 应用程序,它使用 LinkedIn OAuth flow 来登录用户,该应用程序在很长一段时间内一直没有问题。但是,最近该过程的 'Step 3: Exchange Authorization Code for an Access Token' 部分出现错误:

System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

由于上述原因,用户无法在我们的应用程序中连接到 LinkedIn。奇怪的是,这只发生在生产服务器 (Windows Server 2012 Standard) 上,但在我们的开发环境和 Azure 中托管的应用程序的阶段版本 (Azure App Service) 中继续正常工作。这当然表明生产服务器本身是罪魁祸首,并且还看到端点需要 TLS 1.2 的 Web 请求可能会在同一服务器上出错并显示以下消息,这进一步指控服务器:

The request was aborted: Could not create SSL/TLS secure channel.

根据此处 Authenticating with OAuth 2.0 Overview 的文档,对我们假定包含任何 OAuth 端点的 LinkedIn API 的调用现在需要 TLS 1.2。尽管错误消息不同,但研究告诉我们这两种错误消息都可能是由服务器上启用的相同底层 TLS 版本引起的。

这里是出现异常的方法:

public static HttpResponseData DoPostRequest(string uri, string postData)
{
    byte[] byte1 = Encoding.UTF8.GetBytes(postData);

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;

    HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(uri);
    webReq.Method = "POST";
    webReq.ContentType = "application/x-www-form-urlencoded";
    webReq.ContentLength = byte1.Length;

    Stream newStream = webReq.GetRequestStream();
    newStream.Write(byte1, 0, byte1.Length);
    newStream.Close();

    HttpWebResponse resp = (HttpWebResponse)webReq.GetResponse();
    HttpResponseData respData = HttpData.PackageData(resp);

    return respData;
}

具体来说,就是这一行出现连接错误:

Stream newStream = webReq.GetRequestStream();

我们正在继续研究并尝试根据 Microsoft article Transport Layer Security (TLS) registry settings. After restarting the problem still exists. Obviously we're missing something. Note we tested our site at SSL Labs 启用 TLS 1.2,这给我们评分为 B,并且确实表明 TLS 1.2 实际上已启用。

LinkedIn 对此有任何见解或对后续步骤有任何建议吗?

@Hitesh 向我们指出了正确的解决方案 posted 大约比我们早一周(由于某种原因 post 没有出现在搜索中所以我们的 post 重复了他们的):

原帖:

解决方案:

希望这对遇到此问题的人有所帮助