Virtual entities is a recent feature introduced by Dynamics. Using Virtual entities , we can connect to external data source providers and provide them in a Dynamics GUI just like any other entity.
In the Virtual entity we can configure the source as an ODATA V4 provider.
In this particular blog, we will go through an example wherein we will utilize the Query Parameters present in the ODATA V4 Provider data source and show how we can implement a custom security using them.
In the mentioned below example, we will just create an ODATA Web API which will be consumed in the Virtual entity ODATA Source Provider.
For the sake of just explaining the concept, we will just go through the ODATA Controller and not the complete source code which will create the data to be shared with Dynamics.
Step 1 – Creating a Custom Authorization Class.
In this class, we will inherit this class with “AuthorizeAttribute” class available in namespace “System.Web.Http.AuthorizeAttribute”.
We will then override the method “OnAuthorization”. In the implementation, we will read the header variables present in the request. The key specified in the request header will be used later while setting up the virtual entity ODATA Provider source in Dynamics.
// Custom Authorization Class , which is implementing the class AuthorizeAttribute
Step 2 – Adding Custom Authorize Attribute on the ODATAController.
Mentioned below is the code snippet for the same
Step 3 – Specifying the custom request header while Setting up the OData V4 Data Source
Please refer to the below screenshot which shows how we can specify the header parameter in the query header parameters
a) Navigate to Settings -> Administration -> Virtual Entity Data Sources. Click “New” to create a new Data Provider
b) Click “Ok”. In the tab “Request Parameters”, Create a new parameter with Type as “Header”, Name as the “token” key specified in the code in step 1 and value.