5

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.

2
  • 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. Commented Oct 18, 2018 at 11:52
  • @juunas see below for workaround! Commented Oct 19, 2018 at 18:12

3 Answers 3

8

You can use an App Password for your C# console application.

  1. Login to Office Portal. Click on gear in upper right, click Office 365 under "Your App Settings."
  2. Click on Security & Privacy on left and then Additional Security Verification.
  3. Click Create and manage app passwords.
  4. Click Create and give your password a name (maybe the name of your C# application so you remember it later).
  5. Copy the generated password (it will never be shown again).
  6. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you For you answer , but i want to Multi factor Authentication via console app. i have one Crm login id and password and app ask me OPT whenever i login via Browser. i want same things via console app.
3

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

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.