【问题标题】:Facing issue while create the events using MS graph API使用 MS 图形 API 创建事件时面临的问题
【发布时间】:2022-11-11 13:00:09
【问题描述】:

我已经尝试过这段代码来生成令牌:

public async Task Authenticate() {
  MultipartFormDataContent content = new MultipartFormDataContent();
  content.Add(new StringContent(_clientId), "client_id");
  content.Add(new StringContent(_clientSecret), "client_secret");
  content.Add(new StringContent("client_credentials"), "grant_type");
  content.Add(new StringContent(".default"), "scope");
  try {
    var task = _client.PostAsync(new Uri(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", _tenantId)), content);
    var res = task.GetAwaiter().GetResult();

    if (res.StatusCode == System.Net.HttpStatusCode.OK) {
      JsonDocument resJSON = await JsonDocument.ParseAsync(await res.Content.ReadAsStreamAsync());
      _accessToken = resJSON.RootElement.GetProperty("access_token").GetString();

      lock(this) {
        _expiresAt = DateTime.UtcNow.AddSeconds(resJSON.RootElement.GetProperty("expires_in").GetInt16());
      }
    } else
      throw new Exception(res.ReasonPhrase);
  } catch (WebException ex) {
    // handle web exception
  }

}

但我得到了这样的错误

error_description=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: 334xxxx. 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.

跟踪 ID:c8a502xxxx 相关 ID:325a1dxxxxx 时间戳:2022-08-04 13:35:23Z

但是相同的代码在控制台应用程序中工作。在 dll 中使用此代码时会引发异常。所有版本都是相同的 - .net 框架、System.text.json、system.memory 等。

请帮我解决这个问题。

【问题讨论】:

  • 相同的 dll 在新的控制台应用程序中工作。但不适用于 API 应用程序。是否有任何依赖关系?

标签: api microsoft-graph-api


【解决方案1】:

根据this 页面,使用的默认 TLS 版本取决于目标 .net 版本和使用的操作系统。 面向 .net 框架 4.8 应默认为 Windows 10/11 上的 TLS1.2

您使用旧版本的任何更改?或者您在应用程序的某处明确设置 tls 版本?

在异步方法中使用 lock 也是不好的做法,可能会使代码死锁。

【讨论】:

    【解决方案2】:

    当我使用.NET Framework 4.6.1 时,我遇到了同样的问题。将版本切换到4.7.2后,直到我在Web.config中明确指定版本后问题才解决。

    <httpRuntime targetFramework="4.7.2" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多