web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Access CRM Online V9.1 Reporting Services from plugin code

(0) ShareShare
ReportReport
Posted on by 20

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

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 125

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans