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

Authenticating to Dynamics CRM API using a web app? (No-Prompt authentication)

(0) ShareShare
ReportReport
Posted on by

I am trying to connect a web app bot to the Dynamics CRM API, I need to be able to acquire the authorization token for the CRM API without prompting the user for login details.  I can't find any docs on how to achieve this with the latest version of Microsoft.IdentityModel.Clients.ActiveDirectory, any ideas? 

Otherwise how can I connect my web app to the CRM API to create incidents, etc?

Note: This integration is not for Live Assist, but for posting cases to the Dynamics CRM API.

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    Follow below article to Register Application in Azure Active DIrectory.

    docs.microsoft.com/.../walkthrough-register-app-azure-active-directory

    Once this setup is completed, copy Application ID and Create Application use in CRM then grant appropriate permission/security role.

    Manually create a Common Data Service application user

    The procedure to create this user is different from creating a licensed user. Use the following steps:

    Navigate to Settings > Security > Users

    In the view drop-down, select Application Users.

    Click New. Then verify that you are using the Application user form.

    If you do not see the Application ID, Application ID URI and Azure AD Object ID fields in the form, you must select the Application User form from the list:

    Add the appropriate values to the fields:

    Field Value

    User Name A name for the user

    Application ID The Application ID value for the application registered with Azure AD.

    Full Name The name of your application.

    Primary Email The email address for the user.

    The Application ID URI and Azure AD Object ID fields are locked and you cannot set values for these fields.

    When you create this user the values for these fields will be retrieved from Azure AD based on the Application ID value when you save the user.

    Associate the application user with the custom security role you created.

    See this link here for more details - docs.microsoft.com/.../authenticate-oauth

    class SampleProgram

    {

       private static string serviceUrl = "yourorg.crm.dynamics.com";

       private static string clientId = "51f81489-12ee-4a9e-aaae-a2591f45987d";

       private static string userName = "you@yourorg.onmicrosoft.com";

       private static string password = "yourpassword";

       static void Main(string[] args)

       {

           AuthenticationContext authContext =

           new AuthenticationContext("login.microsoftonline.com/common", false);  

           UserCredential credential = new UserCredential(userName, password);

           AuthenticationResult result = authContext.AcquireToken(serviceUrl, clientId, credential);

           //The access token

           string accessToken = result.AccessToken;

           using (HttpClient client = new HttpClient()) {

           client.BaseAddress = new Uri(serviceUrl);

           client.Timeout = new TimeSpan(0, 2, 0);  //2 minutes  

           client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");

           client.DefaultRequestHeaders.Add("OData-Version", "4.0");

           client.DefaultRequestHeaders.Accept.Add(

               new MediaTypeWithQualityHeaderValue("application/json"));

           HttpRequestMessage request =

               new HttpRequestMessage(HttpMethod.Get, "/api/data/v9.0/WhoAmI");

           //Set the access token

           request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

           HttpResponseMessage response = client.SendAsync(request).Result;

           if (response.IsSuccessStatusCode)

           {

               //Get the response content and parse it.  

               JObject body = JObject.Parse(response.Content.ReadAsStringAsync().Result);

               Guid userId = (Guid)body["UserId"];

               Console.WriteLine("Your system user ID is: {0}", userId);

           }

       }

    }

    If found helpful, Please mark my answer verified.

  • Community Member Profile Picture
    on at

    Thank you Bipin, I will mark verified as soon as I have implemented!

  • Suggested answer
    Nishant Rana Profile Picture
    11,325 Microsoft Employee on at

    You can use grant type - client credentials here

    nishantrana.me/.../

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 April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 62 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans