首页 > 解决方案 > MSAL + Graph AcquireTokenForClient 问题

问题描述

间歇性问题或一段时间后停止工作:从 .NET Core WEB API 调用 AcquireTokenForClient 时出现 SSL 错误。

在开发机器上运行良好。在服务器中看到此问题,但不确定何时停止。IIS 服务器在本地运行并使用 MSAL 调用 Azure AD。

直接从 Microsoft Sample 中用于连接到 Graph 的代码......

 app = ConfidentialClientApplicationBuilder.Create(AuthHelper.ClientId)
       .WithTenantId(AuthHelper.Tenant)
       .WithClientSecret(AuthHelper.ClientSecret)
       .Build();

        // a tenant administrator
       `string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
        AuthenticationResult result = null;
        try
        {
            result = await app.AcquireTokenForClient(scopes)
                .ExecuteAsync(System.Threading.CancellationToken.None);
        }

异常:无法建立 SSL 连接,请参阅内部异常。\nTrace
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancelToken)

标签: microsoft-graph-apimsal

解决方案


推荐阅读