Custom integration between Dynamics 365/CDS and SharePoint using C# and SharePoint REST API ? Learn how to create a SharePoint Add-in and generate authentication token–Part 1

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Before I go ahead, while this blog depicts on how you can generate the Authentication token to integrate between Dynamics 365 and SharePoint, this can be applied to any application trying to authenticate with SharePoint online to consume SP REST API’s. The methodology presented here can be applied for all applications.

Your day as a consultant can throw a lot of surprises and this was one of them. We had a custom integration between Dynamics 365 online and SharePoint. online And the connection was being completed using username and password authentication by consuming Sharepoint REST API services.

And one fine day this stopped working. There were some access policy changes on Azure and now the code was not able to generate a request digest using username-password credentials. It was always coming as null and authentication was failing. Moreover client was also not okay to use a service or end-user account for authentication.

If you are on the same boat, don’t be worried. This blog is explicitly on how you can handle this scenario. And that is using SharePoint add-in.

There are multiple ways to register SharePoint add-in such as using Visual Studio, the Seller Dashboard, or an AppRegNew.aspx page. In this blog post we will register add-in using AppRegNew.aspx in tenant which is one of the recommended approaches.

To do this we need global administrator privileges which is SharePoint Administrator role in SharePoint site. Let us now try to register your add-in in the following steps:

Step 1: Go to <site-colleciton-url>/_layouts/15/AppRegNew.aspx using browser.

clip_image002

Step 2: Fill up the details to create add-in

 

· Client Id – Add in ID basically a Guid that can be generated (Generated button is used to generate Guid) or paste Guid into AppRegNew.aspx

· Client Secret – Add in Secret basically a string that can be generated using Generated button. Usually the secret expires in one year.

· Title – Name of the add in

· App Domain – The host name of the remote component of the SharePoint Add-in. he add-in domain must match the URL bindings you use for your web application. Do not include protocol (“https:”) or “/” characters in this value. If your web application host is using a DNS CNAME alias, use the alias. Examples: www.localhost.com, www.contoso.com:3333 and www.scholarship.com

· Redirect Uri –The endpoint in remote application. The value must be a complete endpoint URL including the protocol, which must be HTTPS. For example: https://www.localhost.com, https://www.contoso.com/Default.aspx

Step 3: Provide all the details and click Create.

clip_image004
clip_image005

Now that we have created the add-in, it’s now time for providing the app the required permissions to your sitecollection. In the next blog will shall be doing the same. Make a copy of your application details that you just created. We shall need it in the next blog.

Hope this helps!

Debajit Dutta

(Microsoft MVP)

Published by

Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s