I'm working on an application to obtain data through OAuth of Dynamics 365 to do this use the following example
https://www.youtube.com/watch?v=Td7Bk3IXJ9s
public static async Task Auth()
{
string URL = "https://grupolg.api.crm.dynamics.com/api/data/v9.1/";
AuthenticationParameters API = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(URL)).Result;
//APP KEY, SECRET KEY
ClientCredential Creds = new ClientCredential("hidden for security", "hidden for security");
AuthenticationContext authContext = new AuthenticationContext(API.Authority);
string token = authContext.AcquireTokenAsync(API.Resource, Creds).Result.AccessToken;
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0,2,0);
httpClient.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer",token);
HttpResponseMessage res = await httpClient.GetAsync(URL+"/contacts$top=1");
}
}
but I get the following error:
The error is caused by the ADAL version you're using and how the authority URL is generated.
If you downgrade the Microsoft.IdentityModel.Clients.ActiveDirectory
library version to 3.9.18 you'll be able to connect without problems. There's an open bug in GitHub where you can track its progress or comment to add more information to get a definitive fix for it.