MicrosoftOnline 持有者令牌检索在一台服务器上工作,但在另一台服务器上不起作用

MicrosoftOnline Bearer Token retrieval works on one server but not the other

提问人:MarkEMarkEMark 提问时间:11/17/2023 最后编辑:MarkEMarkEMark 更新时间:11/17/2023 访问量:13

问:

我有一项服务已经在 Windows 服务器上成功运行了好几年(现在仍然如此)。

客户希望将容量增加一倍,因此希望它在第二台 Windows 服务器上运行。但是,它失败了。

失败的部分是从 Microsoft Online 检索持有者令牌。

第二台服务器已被确认能够在 Soap UI 中执行此操作

SoapUI Success

报告异常的关键是

System.AggregateException: One or more errors occurred. 
---> System.Net.Http.HttpRequestException: An error occurred while sending the request. 
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. 
---> System.ComponentModel.Win32Exception: The client and server cannot communicate
, because they do not possess a common algorithm

失败的功能是这样的 - 它是 VB.NET(不要问......

    Public Async Function GenerateAccessToken(baseURL As String, authorization As String, clientID As String, clientSecret As String, resource As String) As Task(Of String)
        Dim responseString As String

        Try
            Dim client As HttpClient = HeadersForAccessTokenGenerate(baseURL, authorization)
            Dim body As String = ""

            Dim request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Post, client.BaseAddress)
            request.Content = New StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded")

            Dim postData As List(Of KeyValuePair(Of String, String)) = New List(Of KeyValuePair(Of String, String))()
            postData.Add(New KeyValuePair(Of String, String)("grant_type", "client_credentials"))
            postData.Add(New KeyValuePair(Of String, String)("client_id", clientID))
            postData.Add(New KeyValuePair(Of String, String)("client_secret", clientSecret))
            postData.Add(New KeyValuePair(Of String, String)("resource", resource))
            request.Content = New FormUrlEncodedContent(postData)

            Dim tokenResponse As HttpResponseMessage = client.PostAsync(baseURL, New FormUrlEncodedContent(postData)).Result

            responseString = Await tokenResponse.Content.ReadAsStringAsync()
        Catch ex As HttpRequestException
            Throw ex
        End Try

        'Return If(responseString.Contains("error"), responseString, token.AccessToken)
        Return (responseString)
    End Function

只是重申 - 此代码在一台服务器上成功,但在另一台服务器上不成功,并且在 SoapUI 中适用于两台服务器。

我只处于可以向客户提问的水平,无法直接访问服务器,因此我必须相信客户的话,即服务器的配置相同。

我可以让他们检查什么?

OAuth-2.0 访问 持有者令牌

评论


答:

0赞 MarkEMarkEMark 11/17/2023 #1

我可能已经解决了这个问题。我暂时无法与客户核对,但排队

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls13

在我的开发系统上重现了他们的错误,所以我猜测

System.Net.SecurityProtocolType.SystemDefault 实际上对于这两个服务器是不同的。

所有可能值的

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

是使它在我的开发 PC 上再次运行的那个。

我发布这个是因为它可能会帮助其他人。