Multi-factor authentication is enabled on the Azure portal, and it will send a OTP whenever I log in to Dynamics 365. I want to login with MFA in a C# console application.
-
The only way to do MFA is to redirect the user to login / show them a webview in a pop-up / use device code authentication. Any way you choose, the user must go through auth in a browser.juunas– juunas2018-10-18 11:52:30 +00:00Commented Oct 18, 2018 at 11:52
-
@juunas see below for workaround!Josh Painter– Josh Painter2018-10-19 18:12:49 +00:00Commented Oct 19, 2018 at 18:12
3 Answers
You can use an App Password for your C# console application.
- Login to Office Portal. Click on gear in upper right, click Office 365 under "Your App Settings."
- Click on Security & Privacy on left and then Additional Security Verification.
- Click Create and manage app passwords.
- Click Create and give your password a name (maybe the name of your C# application so you remember it later).
- Copy the generated password (it will never be shown again).
- Use your normal username and this new password - it will skip multi-factor authentication.
You can create as many App Passwords as you need for legacy apps that don't work with MFA. Try not to reuse them - just create as many as you need. This way you can easily go back and revoke specific passwords when you don't need them any more.
1 Comment
You can access or login to multifactor enabled CRM user programmatically. You would need to use CRM user ID and app password that was generated while enabling multifactor authentication. Follow following article, https://community.dynamics.com/365/b/dynamicscrmconsultant/archive/2018/06/13/programmatically-authenticate-multi-factor-enabled-dynamics-365-crm-environment
Use CRM Id and app password instead of your default password.
Hope this helps.
Comments
you can use ClientSecret connection string to achieve that usign SDK either CrmSericeclient(https://www.nuget.org/packages/Microsoft.CrmSdk.XrmTooling.CoreAssembly) or new .Net core ServiceClient(https://www.nuget.org/packages/Microsoft.PowerPlatform.Dataverse.Client/).
Here is example https://learn.microsoft.com/en-us/power-apps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect
look for section (ClientId or Client Secret based authentication)