If you have a Console App that authenticates to D365 using a credential (typically, an Administrator) but now the administrator is setup for Multi-Factor authentication, your Console App won’t work. So here’s what you can do.
If you first want to check out about enabling Multi-Factor Authentication, you can check my blog post on it here – Office 365 Admin: Quickly Enable Multi-factor authentication for users
Standard Authentication vs MFA enabled User
When there’s not MFA enabled for Dynamics 365 (Office 365) account credentials, you are able to connect to the organization with no issues and get the CRMServiceClient in your application easy.
But, if you have Multi-Factor Authentication enabled for a credential that is used in Console Apps to connect to D365, the Console App will not connect and the CrmCerviceClient will have null as below with the error ‘Unable to Login to Dynamics CRM’
Managing App Passwords on Azure Portal
Once you have multi-factor authentication enabled for your account, you can go to portal.azure.com and manage App Passwords as follows –
- In Azure Portal, go to your account settings.
- Then, go to Additional security verification
- Look for App Passwords
- You can manage and create more passwords here
- Create a password if you don’t want to use a default one or want to use different passwords for different apps. Give it a suitable name and click Next
- Copy the password as it is the only time it will be displayed.
- And you can see your passwords as you create them
Implementing App Passwords in Console App
As the name suggests, App Passwords will let you create special passwords for applications to authenticate to Dynamics 365 without needing to go through multi-factor authentication like when you’re running a Console App to connect to Dynamics 365
- Go to the Password in the credentials in the App.Config of the Console Application
- And replace it with the App Password
- Now, Build the application and run it. It will authenticate successfully.
Hope this helps! 🙂