Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Connecting to MFA enabled Dynamics 365 CRM instance through console application

(0) ShareShare
ReportReport
Posted on by 505

Hello Experts,

I'm trying to connect to dynamics 365 CRM instance through console application but getting 'Unable to login to CRM' error.

Here is my code.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
string connectionString = "AuthType=ClientSecret; url=myorg.crm.dynamics.com; ClientId=b77e2b5a-3946-485e-########; ClientSecret=s.tOrEuew_QTuGxV8Y0v4iTK######;

CrmServiceClient crmServiceClient = new CrmServiceClient(connectionString);
if (crmServiceClient != null && crmServiceClient.IsReady)
{
Console.WriteLine("\nConnection successful.");
}

I performed all the steps mentioned in this link:

https://nemely.com/blog/connect-to-multi-factor-enabled-d365-cds-programmatically-online-9-1/

Thanks,

Priyank

  • Suggested answer
    MMK Profile Picture
    MMK 745 on at
    RE: Connecting to MFA enabled Dynamics 365 CRM instance through console application

    Hi

    for any body who is struggling to connect old Console Application code with MFA Enabled CRM

    To Connect MFA Enabled Dynamics CRM with C# you just need to use App Password instead of your Password remaining every thing remains same as it was

                   string connectionString = GetServiceConfigurationfromAppCOnfig();

                  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                  CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);                

                  _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

                  WhoAmIResponse whoAmIResponse = (WhoAmIResponse)_orgService.Execute(new WhoAmIRequest());

    Follow the Steps to generate App password

    community.dynamics.com/.../connecting-to-mfa-enabled-dynamics-365-v9-x-crm-instance-through-c-or-console-app

  • Suggested answer
    Rui Carvalho Profile Picture
    Rui Carvalho on at
    RE: Connecting to MFA enabled Dynamics 365 CRM instance through console application

    Hello Priyank

    You are using WS Trust authentication and that's deprecated.

    docs.microsoft.com/.../authenticate-office365-deprecation

    Try to go with this sample instead:

    docs.microsoft.com/.../sample-simplified-connection-quick-start

    Or you can download the whole sample here:

    github.com/.../QuickStartCS

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans