My requirement is to Sync my database record to Dynamic 365 and also to authenticate the user.
I am trying with this code but it is not helping me out, Please help me to connect and resolve it
string api = "ujwl.api.crm8.dynamics.com/.../v9.0";
AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(api)).Result;
var creds = new ClientCredential("xxx", "xxx");
AuthenticationContext authContext = new AuthenticationContext(ap.Authority);
var token = authContext.AcquireTokenAsync(ap.Resource, creds).Result.AccessToken;
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
HttpResponseMessage response = await httpClient.GetAsync("ujwl.api.crm8.dynamics.com/.../accounts$top=2");
}
I am not able to authenticate user nor getting the data from the server.
Is this approach correct or I need to go with the different approach.
*This post is locked for comments
I have the same question (0)

Report
All responses (
Answers (