[英]How to use 1.2 TLS version in .NET for getting authenticated to EWS Server
首先是 C# 开发的新手,并尝试将身份验证从基本切换到基于 oauth 的身份验证。 但是,在测试下面的代码时,我得到了折旧异常。
#执行
// Using Microsoft.Identity.Client
var cca = ConfidentialClientApplicationBuilder
.Create(clientId) //client Id
.WithClientSecret(clientSecret)
.WithTenantId(tenantId)
.Build();
var ewsScopes = new string[] { "https://outlook.office365.com/.default" };
try
{
// Get token
var authResult = await cca.AcquireTokenForClient(ewsScopes)
.ExecuteAsync();
this.token = authResult.AccessToken;
}
catch (MsalException ex)
{
Console.WriteLine($"Error acquiring access token: {ex}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex}");
}
#例外
Microsoft.Identity.Client.MsalServiceException
HResult=0x80131500
Message=AADSTS1002016: You are using TLS version 1.0, 1.1 and/or 3DES cipher which are deprecated to improve the security posture of Azure AD. Your TenantID is: 9XXXXXXXXXXXXXXXXXXf. Please refer to https://go.microsoft.com/fwlink/?linkid=2161187 and conduct needed actions to remediate the issue. For further questions, please contact your administrator.
Trace ID: 57531a5a-2797-4f77-bc73-11b1e4355800
Correlation ID: 4295ecdd-7aa1-458f-8e6a-03fda78ec30f
Timestamp: 2022-07-25 03:32:33Z
Source=Microsoft.Identity.Client
我尝试使用ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
不幸的是,这不起作用。 如果有人可以导航以解决上述异常,我们将不胜感激。
也许这可以帮助:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
在代码启动的地方添加这一行(必须尽快到达该行),不要费心添加| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.