Inkey Solution Logo
banner

Blogs

Connection to Dynamics 365 and SharePoint Authentication Using ClientId & ClientSecret: Part 1

, January 8, 2021 4306 Views

I have come across various requirements from clients where it was more feasible to go with creating the C# console application for bulk processing the records in D365 CRM based on complex scenarios like updating the closed case entity records or uploading the files to SharePoint at specific location, or any scenarios that needed custom implementation. We also have different approaches to connect to the Dynamics 365 CRM or SharePoint using C# code to perform specific tasks. We can also create the Azure Service App (WebApi) or Window Form Application to perform aforesaid tasks.

Typically, developers connect with the D365 CRM or SharePoint using the Username and Password of the licensed user where these credentials will be stored into the App.Config file of the C# console application. But this approach has below cons that are to be addressed:

  • Whenever the password of the user is reset, then it should be updated in the App.Config file as well
  • The user should be a licensed (paid) user

To overcome the aforesaid points and in order to choose the appropriate approach, we can make use of the ClientId and ClientSecret instead of the Username and Password. Also, we can make use of Application User that does not require any licences (it’s free).

Follow the below steps to connect to the D365 CRM or SharePoint using C# Code.

Connection to D365 CRM:

Generate ClientId and ClientSecret at Azure:

  • Navigate to Azure Active Directory -> App registrations -> New Registration.

  • Enter appropriate name and hit Register button. You will see the Application ID.

  • Once the Application is created, copy the “Application Id (Client Id)” of the Application and save it for future reference. Add permission to grant D365 CRM. To do that, click on “+ Add a permission” – > select “Dynamics CRM”.

  • Check the user_impersonation check-box on the upcoming screen and hit “Add permissions” button.

  • Click on “Grant admin consent for Org” button and confirm it. You require administrator role to do it.

  • Let’s generate the Client Secret, go to Certificates & Secrets -> + New client secret, enter description and select appropriate validity, then click “Add” button

Create Application User in D365 CRM:

  • Login in into Dynamics 365 CRM and navigate to Settings – > Security -> User. Then, select Application Users view.

  • Click “+ New” button and select to Application User form.

  • Here Application ID must be the same as Azure AD App created.

  • After that, Assign System Administrator or equivalent role to the newly created application user.

In the next blog here we will take up the task of writing the code to connect using what we have done so far. See you next week.


ATM Inspection PowerApp to ease ATM inspection and report generation process.
https://powerapps.microsoft.com/en-us/partner-showcase/inkey-solutions-atm-inspection/

Insert data into Many-to-Many relationship in Dynamics CRM very easily & quickly, using the Drag and drop listbox.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/drag-and-drop-listbox

Comply your Lead, Contact, and User entities of D365 CRM with GDPR compliance using the GDPR add-on.
https://www.inkeysolutions.com/microsoft-dynamics-365/dynamicscrmaddons/gdpr

Create a personal / system view in Dynamics CRM with all the fields on the form/s which you select for a particular entity using the View Creator.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/view-creator

mm

Inkey

INKEY is your solution partner.
Our focus is to deliver you in-time intelligent innovative solutions ("key") for the problems in hand. Maintaining a quality standard right from the inception of a project is our top most priority.

Our team of talented professionals will execute your projects with dedication and excellence. We take ownership and accountability for the effort that goes into meeting our client’s needs.

Years of experience and proven success of delivering innovative custom solutions.

More posts by

2 responses to “Connection to Dynamics 365 and SharePoint Authentication Using ClientId & ClientSecret: Part 1”

  1. […] our previous post, we saw what needs to be done in Azure and Dynamics 365. Now we will see the code […]

  2. […] our previous blog posts for using clientid/client secret part1 and part2, we used a Nuget package that has been deprecated. The rest of the parts of the blogs […]

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 2 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Drop file here

Would you like to digitize your business and put it on the cloud?
Do you need clear, concise reports for your organization?