Search code examples
office365console-applicationdynamics-crm-onlinemulti-factor-authentication

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


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?


Solution

  • 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://learn.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://learn.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).