Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Error when trying to switch CrmServiceClient from the Office365 AuthType to OAuth AuthType

(0) ShareShare
ReportReport
Posted on by 5

So Im following this article to try and get our authentication switched over from Office365 to OAuth authentication because the Office365 auth type is deprecated: https://docs.microsoft.com/en-us/power-apps/developer/data-platform/authenticate-office365-deprecation#how-do-i-know-if-my-code-or-application-is-using-ws-trust

I have been trying various different connection strings for days now and i cant get this error to stop being thrown: "Unable to Login to Dynamics CRMOrganizationWebProxyClient is null"

This error isnt really helpful at all and i don't understand whats wrong. Here is my connection string:

AuthType=OAuth; Url=https://XXX.crm.dynamics.com; Username=XXXXXXXXXXX; Password=XXXXXXXXXXX; AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97; LoginPrompt=Never

And Here is how I'm using it in my C# application:

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            string crmConn = ConfigurationManager.ConnectionStrings["CRMConnection"].ConnectionString;


            var service = new CrmServiceClient(crmConn);
            return service;

But "service" always returns the above error. What am i doing wrong? How can i find a more useful error?

  • Suggested answer
    RE: Error when trying to switch CrmServiceClient from the Office365 AuthType to OAuth AuthType

    Hi,

    Just follow the step.

    Downloads the latest version of 

    • using Microsoft.PowerPlatform.Dataverse.Client;
    • using Microsoft.Xrm.Sdk;

    Just follow the below program 

    • public static void Connect()
    •         {
    •             //  log.LogInformation("C# HTTP trigger function processed a request.");
    •             ServiceClient crmServiceClient = null;
    •             System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
    •             var clientId = "8182544c-3485-4bc3-9884-81617d48e39a";
    •             var clientSecret = "8jm7Q~nhPHGP0Ccl-6a5ow2Tivf4LzADLdZMR";
    •             var organizationUrl = "">org13ffb2c4.crm8.dynamics.com/";
    •             string connectionString = "Url=" + organizationUrl + "; " +
    •             "AuthType=ClientSecret; " +
    •             "ClientId= " + clientId + "; " +
    •             "ClientSecret=" + clientSecret;
    •             crmServiceClient = new ServiceClient(connectionString);
    •             if (crmServiceClient.IsReady)
    •             {
    •                 CreateRecord(crmServiceClient);
    •             }
    •         }
    •         private static void CreateRecord(ServiceClient crmServiceClient)
    •         {
    •             try
    •             {
    •                 Entity newAccount = new Entity("account");
    •                 newAccount["name"] = "Account is crated through Azure";
    •                 crmServiceClient.Create(newAccount);
    •                 //Write the program here
    •             }
    •             catch (Exception)
    •             {
    •                 throw;
    •             }
    •         }

    Thanks ,

    Arshad 

    Please like and subscribe my YouTube Channel and follow my blog for latest interview question and answer.

    www.youtube.com/.../videos

    https://juniorcrmblog.blogspot.com/

    https://juniorazurecrm.blogspot.com/

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: Error when trying to switch CrmServiceClient from the Office365 AuthType to OAuth AuthType

    Hi,

    Have you tried updating the package to latest version?

    www.nuget.org/.../

    I created new console app and I use same code as yours and it works.

    You can download my project from below link and update config file with your credentials and URL.

    github.com/.../WorkWithCsharp

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans