Hello Experts,
I'm currently trying to access with ADAL authentication Token, but this error is happening
Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
string resource = "https://ServerURL.crm.dynamics.com/";
HttpResponseMessage response;
string clientId = "XXXXXXXXXXXXXX";
string clientSecret = "XXXXXXXXXXXXXX";
string authorityUri = "https://login.microsoftonline.com/"Domain"/oauth2/authorize"; // i tried this "login.microsoftonline.com/Tenantid" as guide, and I got same issue
AuthenticationContext authenticationContext = new AuthenticationContext(authorityUri, true);
var credential = new ClientCredential(clientId, clientSecret);
var result = await authenticationContext.AcquireTokenAsync(resource, credential);
var token = result.AccessToken;
HttpClient request = new HttpClient();
request.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, completeUrl);
req.Method = HttpMethod.Post;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
response = await request.SendAsync(req);
var responseText = await response.Content.ReadAsStringAsync();
var x = responseText.LastIndexOf("ReportSession=");
var y = responseText.LastIndexOf("ControlID=");
string[] ret = new string[2];
ret[0] = responseText.Substring(x + 14, 24);
ret[1] = responseText.Substring(y + 10, 32);
I followed this link to create the Authentication token: https://www.c-sharpcorner.com/article/generate-access-token-for-dynamics-365-single-tenant-server-to-server-authentica/
i hope some help, Kind Regards
Juan Camilo