web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

OAuth CrmServiceClient CRM connection issues

(0) ShareShare
ReportReport
Posted on by 255

Hi

I can't connect to CRM online with OAuth CrmServiceClient.

Whenever I try it times out. I'm going mad with this!!!

My test code is below.

Does the user need particular permissions or anything?

(.Net version 4.6.2)

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System;


public partial class  c2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string ConnectionString = "AuthType=OAuth;Username=xxx@xxx.com;Password=xxx;Url=https://xxx.crm4.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Never";

        CrmServiceClient svc = new CrmServiceClient(ConnectionString);

        if (svc.IsReady)
        {
            var myContact = new Entity("contact");
            myContact.Attributes["lastname"] = "Test";
            myContact.Attributes["firstname"] = "User1";
            svc.Create(myContact);
        }
    }
}

I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Hello Stuie,

    Can you try to update the Core Assembly with latest version and check after that?

    community.dynamics.com/.../unable-to-connect-with-dynamics-365-using-c-web-api

    Thank you,

    Amit Katariya

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    use the ClientSecret authentication with an azure App Registration, it's easier to setup

  • Stuie Profile Picture
    255 on at

    Something like this?

           string ConnectionString = "AuthType = ClientSecret;url=xxxx.crm4.dynamics.com;ClientId=0b2285ce-75c9-xxxx;ClientSecret=b6512071-93f8-xxxx";

  • Guido Preite Profile Picture
    54,086 Moderator on at

    yes, you will need to create an Azure App Registration and after add the application user inside Dynamics

  • Stuie Profile Picture
    255 on at

    OK thanks. I've done everything but can't find the Application Users section in CRM.

    I've checked the form and view is enabled.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Hello Stuie,

    You will need "Azure Active Directory App". if you already have then you just need to provide Dynamics 365 API permission to it and create a application user in the Dynamics 365 and link with this Azure Active Directory Application.

    Please refer below Article which will guide you step by step for the connection.

    optimallogics.com/.../

    Thank you,

    Amit Katariya

  • Stuie Profile Picture
    255 on at

    Hi. Thanks.

    I've been through all that and set up everything but in Dynamics there's no Application User list or form to add one.

    If I click Add new user I need to add a new license which I don't want to do.

    Can I edit an existing user to give them them app access?

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    follow the first part of this blog post for the instructions benediktbergmann.eu/.../

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    Hello, 

    I guess you do not require the licence for the Application user. Because it is used for the Authentication purpose so it will be considered as the non interactive user. 

    https://medium.com/capgemini-microsoft-team/dynamics-365-application-users-no-additional-license-required-and-no-limit-on-quantity-4bdc49f8ce2d

    Thanks, 

    Amit katariya

  • Stuie Profile Picture
    255 on at

    Thanks for the help!

    I have managed to connect via a Console App using the code below.

    How can this be altered to work in a C# webservice?

    using System;

    using Microsoft.IdentityModel.Clients.ActiveDirectory;

    namespace Dynamics365ServerToServerAuthentication

    {

       class Program

       {

           static void Main(string[] args)

           {

               const string authorityUri = "login.microsoftonline.com/.../authorize";

               const string d365Url = "xxxx.crm4.dynamics.com";

               const string clientId = "0589294b-xxxxxxx";

               const string clientKey = "0A27Qxxxxx";

               ClientCredential clientCredentials = new ClientCredential(clientId, clientKey);

               AuthenticationContext authenticationContext = new AuthenticationContext(authorityUri, false);

               try

               {

                   var authenticationResult = authenticationContext.AcquireTokenAsync(d365Url, clientCredentials).GetAwaiter().GetResult();

                   Console.WriteLine($"Connection success: {!string.IsNullOrEmpty(authenticationResult.AccessToken)}");

               }

               catch (Exception e)

               {

                   Console.WriteLine(e);

               }

               Console.ReadKey();

           }

       }

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 170 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 155

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans