oauth2.0 如何 在 . NET 中 使用 1.2 TLS 版本 获得 EWS 服务 器 的 身份 验证

bz4sfanl  于 2022-11-21  发布在  其他
关注(0)|答案(1)|浏览(177)

首先,我是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;
不幸的是,这不起作用。如果有人能导航解决上述异常,将不胜感激。

beq87vna

beq87vna1#

也许这能帮上忙:

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

添加这一行代码(必须尽快到达该行),并且不要添加| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
对我很有效。

相关问题