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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 97

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

I have the same question (0)
  • PranavShroti Profile Picture
    4,510 on at

    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.

  • Shrikantbhongade Profile Picture
    97 on at

    400 bad request error

  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at

    Check this link..

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans