MFA is becoming a common thing, as joyous as it is to use 🙂
I have a C# app that connects to Dynamics CRM/365 and I had to update it to support Microsoft Azure MFA.
I couldn’t really find any definitive guide out there, i had to cobble all different things together to get a working solution.
I hope this guide helps out some other poor sucker like me.
1. I had to update my application to use the modern CRM Tooling method of connection.
I added the following in Nuget to my solution – the key being the CrmTooling which supports the new connection string method of connecting.
In my code, i changed the way i obtained an IOrganizationService to the below (simplified):
string conn = "my connection string"; IOrganizationService _crmService; CrmServiceClient service = new CrmServiceClient(conn); _crmService = (IOrganizationService)service.OrganizationWebProxyClient != null ? (IOrganizationService)service.OrganizationWebProxyClient : (IOrganizationService)service.OrganizationServiceProxy;
This gets me a connection using the new Tooling DLL and a CRM Connection string.
Next step, you need to create an application in Azure AD. I followed this guide.
The trick is the Redirect URI – i wasn’t working with a web app – I ended up using http://localhost
Finally, constructing a connection string that would work with the new registered Azure App.
AuthType=OAuth;Url=https://yourcrm.crm.dynamics.com;AppId=yournewappid;RedirectUri=http://localhost;
Now when you go to connect, the Microsoft Sign In assistant pops up and handles the authentication to the CRM Instance.
And, if you have MFA turned on, you are also prompted with MFA.
Happy Days!