Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how to login in Dynamics CRM using Azure Key id using C#

Posted on by 95

Hello All,

I have created Apps in Azure. I am able to get Application Id, Client Secret Id(Expire Key), and Tenant Id(Directory Id). I am using the following code. But Bad Request 400 error message raising.

I have created Azure apps using the following URL.

https://community.dynamics.com/crm/b/passiondynamics/archive/2018/12/17/register-dynamics-crm-app-with-azure-for-oauth-2-0-authentication

Please review the following code.

string client_id = "<Client_Id>";
string client_secret = "<client_secret >";
string resource = "https://demo.crm.dynamics.com/";
string urldata = string.Format("login.microsoftonline.com/&lt;tenant_id>/oauth2/token?" + "grant_type=client_credentials&client_id={0}&client_secret={1}&resource={2}", Uri.EscapeDataString(client_id), Uri.EscapeDataString(client_secret), Uri.EscapeDataString(resource));

var request2 = (HttpWebRequest)HttpWebRequest.Create(urldata);
request2.Headers.Add("x-ms-version", "2012-08-01");
request2.Method = "POST";
//request2.ContentType = "application/json";
request2.ContentType = "application/x-www-form-urlencoded";
request2.KeepAlive = false;
Stream dataStream = request2.GetRequestStream();
WebResponse response2 = request2.GetResponse();
dataStream = response2.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
using (var streamReader = new StreamReader(response2.GetResponseStream()))
{
Console.WriteLine("open");
var resultss = streamReader.ReadToEnd();
Console.WriteLine(resultss.ToString());
Console.ReadKey();
}

*This post is locked for comments

  • Suggested answer
    PranavShroti Profile Picture
    PranavShroti 4,510 on at
    RE: how to login in Dynamics CRM using Azure Key id using C#

    Check this link..

    docs.microsoft.com/.../gg327838(v=crm.8)

  • Shrikantbhongade Profile Picture
    Shrikantbhongade 95 on at
    RE: how to login in Dynamics CRM using Azure Key id using C#

    400 bad request error

  • PranavShroti Profile Picture
    PranavShroti 4,510 on at
    RE: how to login in Dynamics CRM using Azure Key id using C#

    I did't understand your question, is your login failing? what error you are getting when you run this code.

    Share more details so that we can help.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans