Create, Configure And Deploy Provider Hosted Add-In For SharePoint Online - Part One

SharePoint provides two types of add-ins (Previously Apps)

  • SharePoint Hosted Add-ins
    Used to deploy SharePoint resources like pages, lists, workflows, custom content types, list templates, Web Parts and so on. It cannot contain custom server side object model code but supports REST and JSOM.

  • Provider hosted Add-ins
    Used to deploy components outside the SharePoint Farm. It can include a web application, web service or database that is deployed outside SharePoint.
In this article series we will see how to deploy a provider hosted add-in to SharePoint Online in Office 365. Here the Website will be hosted in Azure and the App will be installed in SharePoint Online. Thus the core logic will be abstracted away from SharePoint farm. Upon opening the app in SharePoint Online, the redirection happens to the Website hosted in Azure. The article will be divided into 2 parts.
  • Create, Configure and Deploy remote add-in web to Azure
  • Deploy add-in to SharePoint online
Prerequisites

Ensure that you have the below subscription to get started with the development
  • Azure Subscription - The web site will be hosted in Azure. So ensure that we have an active Azure Subscription.
  • Office 365 SharePoint Online Subscription - We will need a developer Site to which the app will be deployed
Create, Configure and Deploy remote add-in web to Azure

Spin up Visual Studio and Select ‘SharePoint Add-in’ template.

Azure

Specify the SharePoint Online Developer Site URL and select Provider-hosted option. Click on Next.

Azure

This will open up the Office 365 authentication pop up. Enter the Office 365 credentials.

Azure

It will automatically select ‘SharePoint Online’ version. If not select it manually.

Azure

You can either proceed with web Forms or MVC Web Application. Here I am moving ahead with MVC.

Azure

Since we are deploying the Web to Azure, we will be making use of Azure Access Control Services (Known as Low Trust Authentication). If we were deploying the web to an on premise IIS server we could have used a signed certificate (known as High Trust).

Azure

Click on Finish. This will create the Project structure for us.

Azure

Thus you can see that there are two sections in the created solution structure below,
  • OfficeProviderHostedAdd-in - it will be deployed to the SharePoint Online Site.
  • OfficeProviderHostedAdd-inWeb - it will be deployed to Azure.


If we expand the Controller folder, we can see the controller files.

Azure

Within the Views Folder we can see the View file. We will be getting the current user name in the controller and will be displaying it using the view as shown below.

Azure

Azure

We can update the MVC logic as required in the Controller and View files. MVC implementation is similar to the .NET counterpart. Let’s see what we have to do to get the web site deployed into Azure. Right click the add-in web and select ‘Publish’.

Azure

Select Azure Web Apps and click on Next.

Azure

This will open up the Azure Subscription Authentication page. Enter the credentials and click on Sign In.

Azure

Upon Successful Authentication, It will list out exiting web apps. Let’s create a new one.

Azure

Add the details for the new web app and click on Create.

Azure

It will start provisioning the Web App.

Azure

Click on validate connection to test the connection. Once it succeeds click on Publish.

Azure

This will publish the web add-in to Azure.

Azure

It will open up the new web app but will show the below error. This is because we are only half way through and have to update the add-in settings as well. Make a note of the below URL as we will be using it to register the add-in.

Azure

Register the Add-in in SharePoint Online

Head over to the SharePoint Developer Site and append ‘/_layouts/15/appregnew.aspx’ to the end of the URL. In my case it is: ‘https:// playground.sharepoint.com/sites/Playground/_layouts/15/appregnew.aspx’. This will open up the add-in registration page.

Azure
  • Click on generate next to auto generate the Client Id and Client Secret. This will generate the Client Id and Client Secret which we will have to update in the add-in solution. Note them down. 
  • Specify the title as ‘Office Provider Hosted Add-in’.
  • Specify the app domain of the recently created azure web site ‘officeproviderhostedadd-in.azurewebsites.net’
  • Enter the redirect URL as ‘https://officeproviderhostedadd-in.azurewebsites.net/’ . Make sure that you add ‘https’ to the URL.
Click on Create button.

Azure

This will create the app identifier. Note the entire app identifier details as it will be used later.



Setup Azure Web Site’s App Settings

Now let’s configure the app settings for the recently created Azure web site. In order to do that login to the azure subscription. In the web apps section we can see the previously created web app. In our case it is ‘OfficeProviderHostedAdd-in’.

Azure

Click on the Web App and select ‘Configure’ tab.



Go to the app settings section and add the ‘ClientId’ and ‘ClientSecret’ entries which were created in the SharePoint Online App registration page.

Azure

Click on Save to update the app settings entries.

Azure

This will update the Configuration for the Azure Web App where the App Web Site will be hosted.

Azure

Summary - Thus we saw how to deploy the App Web to the Azure. In the next article we will see how to deploy the app to SharePoint Online in Office 365.

Up Next
    Ebook Download
    View all
    Learn
    View all