Wednesday, 21 July 2021

Get/Post/Delete Requests to Azure AD B2C

 

Get/Post/Delete Requests to Azure AD B2C

 

                     


 

As Azure AD B2C is growing to replace Authentication methodology for Microsoft Dynamics Portals as well as other Applications , there is a growing demand to handle Get/Post/Delete Requests  to Azure AD B2C via C# .Net Code.

 

Below is the Info regarding how to make API Requests to Azure B2C using simple coding approaches and Details reg Pre-release Versions.

Dll\Namespace Required to Acquire Classes to access Microsoft Graph APIs :

1.       Microsoft.Graph

2.       Microsoft.Identity.Client

 

 

 

Above mentioned dlls contain definition for IConfidentialClientApplication which can be used to get AuthProvider as shown below :

 

     IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder

            .Create(clientId)

            .WithTenantId(tenant)

            .WithClientSecret(clientSecret)

            .Build();

 

                  ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

Problem :

ClientCredentialProvider method present in Base  Microsoft.Identity.Client Dll and it is not completely tested and recommended by Microsoft yet as it is still in PreRelease stage and we can’t use it in Production. Also , Visual Studio doesnot recognise ClientCredentialProvider class. Hence, we can proceed with below approach which provides authContext and also helps in performing Get/Delete Requests to Azure AD B2C.

 

Solution :

Set below Configurations in App.Config :

            string clientId = ConfigurationManager.AppSettings["b2c:ClientId"];

            string clientSecret = ConfigurationManager.AppSettings["b2c:ClientSecret"];

            string tenant = ConfigurationManager.AppSettings["b2c:Tenant"];

 

      // The app registration should be configured to require access to permissions

        // sufficient for the Microsoft Graph API calls the app will be making, and

            // those permissions should be granted by a tenant administrator.

            var scopes = new string[] { "https://graph.microsoft.com/.default" };

            // Configure the MSAL client as a confidential client

            var confidentialClient = ConfidentialClientApplicationBuilder

                .Create(clientId)

                .WithAuthority($"https://login.microsoftonline.com/$tenantId/v2.0")

                .WithClientSecret(clientSecret)

                .Build();

 

            // Build the Microsoft Graph client. As the authentication provider, set an async lambda

            // which uses the MSAL client to obtain an app-only access token to Microsoft Graph,

            // and inserts this access token in the Authorization header of each API request.

            GraphServiceClient graphServiceClient =

                new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) => {

 

                    // Retrieve an access token for Microsoft Graph (gets a fresh token if needed).

                    var authResult = await confidentialClient

                        .AcquireTokenForClient(scopes)

                        .ExecuteAsync();

 

                    // Add the access token in the Authorization header of the API request.

                    requestMessage.Headers.Authorization =

                        new AuthenticationHeaderValue("Bearer", authResult.AccessToken);

                })

                );

 

Make Either Get Request to Azure B2C or Delete Requests as shown below :

 

            // Make a Microsoft Graph API query

            graphServiceClient.Users[B2cObjectId/User-Id]

               .Request()

               .DeleteAsync();

        }

 

This helps us to fetch Client Id , Client Secret and Tenant Id from App Settings and Get Token as required and perform necessary operations using simple Requests.

 

 

Sunday, 17 May 2020

Azure Attachment Management & Blob Storage


Configuring Azure Attachment Management and Azure Blob Storage

1.       Download Attachment Manager from Microsoft App Source and install it in your respective Orgs.
2.       Connect to your CRM Instance
3.       Create Azure Storage as shown I pic below:

Once created, open the storage account and scroll down and open the Blobs service. Here, the admin will be able to create the containers that will contain the attachments uploaded via CRM.  Create two global containers (which will be utilised in the Azure Attachment Storage Configuration page) and then create a container for each entity that will map attachments to Azure Blob Storage.
Note: Create two (global) containers named “emailsattachmentcontainer” and “notesattachmentcontainer.” Set the “Public Access Level” of any other containers for their respective entities to “Blob,” as this will enable users to have a preview feature

4.       Now provide access to the users by navigating to Shared Access Signature in Azure portal and create SAS Token by setting Expiry DateTime as shown below :

5.       Now navigate to the Dynamics Azure Attachments and paste SAS token in Configuration window as shown below :

6.       Now enable the Entity for Azure Blob Storage and map Entity in Container window as shown below :

7.       For Email Attachments , map Email entity as shown below :

8.       Provide necessary Access to Users by assigning Security Roles which has Azure Blob Storage Settings, NotesEntityAttachment Settings permissions.


Wednesday, 6 May 2020

Bi-Directional Integration between CRM and other Dot Net Apps


Bi-Directional Integration between CRM and Dot Net App using Azure Components ( No-Code Approach)

Hi All ,

I would like to provide a way to Integrate Dot net App with CRM using Azure Components and no code approach which can be done by leveraging Azure components like MS Flow , Custom Connectors and WebHooks.

Using Custom Connectors :
A custom connector is a wrapper around a REST API (Logic Apps also supports SOAP APIs) that allows Logic Apps, Power Automate, or Power Apps to communicate with that REST or SOAP API. We can define Actions inside Custom Connectors which can be used later in Azure Functions or MS Flows to integrate with other Product ( This is One-Way Integration.)

How to Create Custom Connector & Actions:

You should have Office 365 Admin privileges in order to create a custom connector and you can create custom connector by following steps :
1.     Login in to : https://make.powerapps.com/
2.     Expand Data Icon and look for Custom Connector option as shown below :





3.     You will see below Screen , where you can create Custom Connector either from Stratch or using Open Api file or even using Postman Collection :

4.     If you proceed with PostMan collection , you can create a collection in Post Man by using POST Method and using Endpoint URL of the App which you want to Integrate to and provide Auth Headers and Body as required. In my scenario , I am using API Key in order to authenticate with the Dot Net app which I want to integrate to as shown below :






5.     Once you prepare Post Man Collection , you can use it Custom Connector as Action to perform Desired Action in the Integrated Application as required as shown below :


Also, you can verify Request page to see whether Endpoints , Headers and Body details are correct.

6.     Once Custom Connector is Created , you can use it inside MS Flow as shown below in order to perform necessary actions as Required.




Example : In my example whenever a Lead is created in CRM , I will trigger a MS Flow which in turn uses Custom Connector to create Record in another Application which I want to integrate.


Two – Way Integration :

Consider you want to create a Lead in CRM whenever lead is created in your Organization’s Dot Net Application , the best way to proceed forward is to use WebHooks ( Again – using Azure Http Web Hook component we don’t need to use any Azure Functions or use Custom Workflows to deal with Web Hooks , we can just do some small configurations which help us in receiving data from other app as shown below :

1.     Whenever an Event takes place in Dot Net app , trigger Http Web Api call to Azure Subscribed URI and use Http Web Hook component in Azure in order to receive the Http Request as shown below :


2.     Provide Subscribe URI ( Endpoint of Integrated App ) and Body as shown below :



3.     Once Web Hook is used inside MS Flow , you will receive Context which contains event details as we have passed and attribute data ( like External Identifier) which we can use inside Flow as decision maker in order to either Create\Update the record inside CRM.

Hope this helps. Happy Integrating!









Tuesday, 28 January 2020

Update\Get Multiselect Optionsets in Workflow | New Workflow Tools Solution from Microsoft


Hello Guys ,
I would like to share a Solution details which can perform multiple operations like Get Multi select Field values or Set Values to Multi-select Fields and much more using Out Of Box workflows without the need to write code in Dynamics 365 CRM Application.

This might be a good news for functional consultants working on Dynamics CRM. Now we can Get ,Set and Map Multiselect Optionset values in Workflows by below approach without the need to write any code.

What Else ?

Not only Multi-select you can perform multiple Actions as mentioned below just by installing one solution from Microsoft AppSource  :

The operations this solution can performed are mentioned as below :
1.  Delete Record Audit History
2. Apply Routing Rules
3. Query Values Step
4. Share Record With Team
5. Share Record With User
6.  Unshare Record With Team
7. Unshare Record With User
8. Check User is in Role
9. Add To Marketing List
10. Remove From Marketing
11. Rollup Functions
12. Add Role To User
13. Qualify Lead
14. Send Email From Template To Users In
15. Get Multi Select Option Set 
16. Map Multi Select Option Set
17. Set Multi Select Option Set


How to perform above all mentioned actions using Workflow ?

Answer for it is follow the below mentioned steps in order to achieve the same:

  1. Download\Install  Dynamics 365 Workflow Tools  solution in your respective Org by downloading it from Microsoft App Source ( this tool is available free of cost in Microsoft Market Place\App Source )

i)                    If you are not aware how to install it , you can check with Devops team \respective Project managers regarding same in order to install it in your org.

  1. Once the solution is Installed , you can verify it in Solutions page as shown below :




Now , you can create a workflow and try to perform operations like Setting Multiselect by following below approach in Workflow :

                                      


  1. Set Multiselect Optionset :

i)                    Once you have selected Set Multiselect Optionset , your step will show as below in Workflow Configuration page




ii)                   Click on Set Properties and set as mentioned in screenshot below (For Testing ,  I am setting Contact Type Multiselect value to specific option value) :

                                


·       Target Record URL: URL of the record to be updated.
·       Attribute Name: logical name of the attribute to be updated.
·       Attribute Values: option set values to be set.


iii)                 Save the workflow and it should update Multiselect based on set value




Tuesday, 26 November 2019

How to Update Addresses Details for Contact\Account while Importing those records using Native Tool

                                                   

Hi All,

I would like to provide small Info regarding How to Update Address Records using Native Tool in CRM Online.

If you are using Native Tool to Import Accounts\Contacts Records into Engage along with Addresses details of respective Accounts \Contacts, Records will get successfully imported to Engage without any issues ., but Address Info will not show in Address Sub-Grid cause Mail Type and Address Number are not updated while Importing Accounts\Contacts as shown below.













As per CRM Configurations , Address Number , Address Type and Mail Type has to be provided for Address Records in order to update Address Relationships with specific Records like Account\Contact. Hence , below is the option which you can use if you are Importing Accounts\Contacts Records using Native Tool.

  1. Import Account\Contact using Native along with Addresses details
  2. Using Advanced Find  , try to retrieve related Addresses for either Accounts\Contacts as shown below :


                                                                       


  1. Retrieve associated Accounts\Contacts Addresses and download the excel sheet with all the required information.
  2. Create columns i.e. Mail Type , Address Number and Address Type in Excel and update the values for the same as per your requirement. Refer Screenshot below for Example.


  1. Reimport Address Records so that existing records will get updated with mentioned info and associated Addresses records will be displayed in Addresses Sub-grid.

Note :
  1. Once after exporting the static excel data sheet – Do not remove columns ( A, B , C) as A holds Primary Key Info and during Import Operation – CRM will perform Primary Key check to verify if record already exists. If record already exists , record will just updated instead of creating new record.

Screenshot for Primary Key Column which is hidden in sheet :




  1. Do Not use CSV file to Upload data to Engage. Use Excel file to update Address Records as CSV upload will try to create new records instead of updating existing ones. Excel will successfully update existing records as shown below:





Thanks for visiting the Blog. 

Monday, 30 September 2019

How to Identify Duplicate Records in SQL Server and MS CRM | Duplicate Detection Jobs in CRM


HI All,

I would like to share some information regarding Identifying Duplicate Records in SQL Server while Migrating data to CRM and Process to Identify\Remove Duplicate Records from CRM using OOB Configurations. I figure most of you might be aware , but as a revise providing you below info.

  1. Identify Number of Duplicate Rows in SQL Server based on selected columns

        Sample Query :
                      
SELECT     ContactId,     [Name],     COUNT(*) occurrences
FROM [Lipscomb_Prod_Migration].[dbo].[Previous_Education_Radius_Produ$]
GROUP BY
               ContactId, [Name]
HAVING     COUNT(*) > 1;

  1. Delete Duplicate Rows in Staging SQL Syntax :

Sample Query :
WITH cte AS (
    SELECT
       ContactId,
 [Name] ,       
        ROW_NUMBER() OVER (
            PARTITION BY
                ContactId, [Name]
               
            ORDER BY
               ContactId, [Name]
        ) row_num
     FROM
        [Lipscomb_Prod_Migration].[dbo].[Previous_Education_Radius_Produ$]
)
DELETE FROM cte
WHERE row_num > 1;



  1. Duplication Detection of Records in CRM :
  • Navigate to Settings > Data Management > Duplicate Detection Jobs
  • Create a New Duplicate Detection Job and select Entity which you want to find duplicate records
  • Run the Detection Job so that below pop-up window will display :


Where we can take necessary action on the record.

Enhanced Full Case form vs Custom Forms in D365 Customer Service

 Balancing Standardization and Flexibility in D365 Case Management — Why Enhanced Case Forms Should Be Your Default ? In D365 Customer Servi...