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.
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/<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