CrmServiceClient 无法使用 Office365 身份验证类型和具有 MFA C# 的用户登录 Dynamics CRM

CrmServiceClient Unable to Login to Dynamics CRM using Office365 auth type and user with MFA C#

我想使用 CrmServiceClient 和 Office365 authType 连接到 crm

string connectionString = "Url=crm_url; Username=crm_user; Password=crm_user_password; AuthType=Office365;";

var crmServiceClient = new CrmServiceClient(connectionString);

如果我使用禁用了 MFA 连接的帐户。

如果我使用启用了 MFA 的帐户,我会遇到错误:“无法登录到 Dynamics CRM OrganizationWebProxyClient 是 nullOrganizationWebProxyClient 是 nullObject 引用未设置为对象的实例”。

我知道最好使用 OAuth,因为它完全支持 MFA。但我不知道在过去 2 周内有什么变化导致它停止工作。用户一直启用 MFA,自查看月份以来没有人更改任何内容。你知道为什么它现在停止工作了吗?

Office365 授权类型已弃用,2021 年 4 月发生了一些变化。没有明确指出它们会导致您的特定问题,但考虑到时间可能相关。
参见 https://docs.microsoft.com/en-us/power-platform/important-changes-coming#deprecation-of-office365-authentication-type-and-organizationserviceproxy-class-for-connecting-to-dataverse

我很惊讶启用 MFA 的帐户 仍然 正常工作。 我最近确实了解到,在 Office 365 管理中,您可以指定免除 MFA 的源 IP 地址。该设置靠近应用程序密码的 enable/disable。也许那里有 IP 地址豁免,而您连接的 IP 最近发生了变化?

当将 AuthType 从 Office365 切换到 OAuth 时,一切都会重新开始工作。所以可能是因为停止支持Office365了。

我正在关注这篇文章: 我是从这个 https://docs.microsoft.com/en-us/powerapps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#named-account-using-office365 to this new one https://docs.microsoft.com/en-us/powerapps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#oauth-using-named-account-in-office365-with-ux-to-prompt-for-authentication.

您需要创建一个 Azure 应用程序并将项目中的包 Xrm pakages 更新到较新的版本才能开始工作。此外,我现在 Microsoft 创建了一个 public 应用程序进行测试(我稍后会尝试 link 这个站点,或者你可以尝试自己找到它)并且你可以使用这个应用程序(但这不是安全的解决方案在我看来)。