I want to authenticate CRM2016 On-Premise (also I m using adfs), not crm online. I m coding crm webapi utility page for my project. I tried to authenticate webapi by 3 ways ;
1- Nothing happens after this code;
HttpClient client = new HttpClient(new HttpClientHandler() { Credentials = new NetworkCredential(userName, password, domainName) });
client.BaseAddress = new Uri("https://crm2016demo.xxxxxx.net:444/");
client.Timeout = new TimeSpan(0, 2, 0);
client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage retrieveResponse = await client.GetAsync("api/data/v8.0/accounts(A2A0FC09-DBBE-E511-80E2-005056B000B7)");
2 - I gave the service url and user credentials as shown below. I m getting 404 error in this line ; return authContext.AcquireToken .
ps: I tried username without giving domainname.
public string ServiceUrl = "crm2016demo.xxxxxxx.net";
public string Authority= "crm2016demo.xxxxxxx.net/main.aspx";
var authContext = new AuthenticationContext(Authority, false);
UserCredential credentials = new UserCredential(Domain + @"\" + UserName, Password);
return authContext.AcquireToken(ServiceUrl, ClientId, credentials);
3 - Also I tried to authenticate with this code (as shown below). When I run the code, Crm online authentication window is opened. Then I wrote username and password, this window shows the crm page with small size. But I want to authenticate crm, I don't need crm page.
var Authority = "crm2016demo.xxxxxxx.net/main.aspx";
var authContext = new AuthenticationContext(Authority, false);
return authContext.AcquireToken(
ServiceUrl, ClientId, new Uri(RedirectUrl));