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

Viewed 826

I would like to connect to crm using CrmServiceClient and Office365 authType

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

var crmServiceClient = new CrmServiceClient(connectionString);

If I use account with disabled MFA connection will be established.

If I use account with enabled MFA I have error: "Unable to Login to Dynamics CRM OrganizationWebProxyClient is nullOrganizationWebProxyClient is nullObject reference not set to an instance of an object".

I know it's better to use OAuth because it fully support MFA. But I don't know what change during last 2 weeks that it stop working. User had enabled MFA for all this time and no one change anything since view months. Do you have any idea why it stoped working now?

2 Answers

The Office365 authtype is deprecated and some changes were happening April 2021. It's not explicitly indicated that they would cause your particular issue but given the timings it could be related.
See https://docs.microsoft.com/en-us/power-platform/important-changes-coming#deprecation-of-office365-authentication-type-and-organizationserviceproxy-class-for-connecting-to-dataverse

I'm surprised that an MFA-enabled account was working anyway. I did learn recently that in Office 365 Admin you can specify source-IP addresses that will be exempt from MFA. The setting is near the enable/disable for App Passwords. Maybe there was an IP address exemption in there and the IP you're connecting from has changed recently?

Everything start working again when whe switch AuthType from Office365 to OAuth. So it's probably because of stop supporting Office365.

I was following this article: I was changng from this one 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.

You need to create an Azure App and update packages Xrm pakages in a project to newer version to everything start working. Also I now that Microsoft create a public App for testing (i will try to link this site later or you can try to find it by yourself) and you can use this app (but it's not safty solution in my opinion).

Related