Friday, June 19, 2015

Step by step to deploy Provider-Hosted app to Microsoft Azure used for SharePoint Online site



There are several examples to deploy Provider-Hosted app to Microsoft Azure for SharePoint Online. I started to follow the example by Microsoft and it worked pretty well. However, there is simply way to achieve the same goal and I would like to provide the steps for new developers in my team.  Please note this example is an empty apps that will not integrate with any Azure or O365 API. The goal is to allow developers to follow easily without too much features. SharePoint apps utilize Azure SSO and O365 APIs will be different and I’ll provide a different deployment procedure in the future.

This example will include the following major steps.

  1. Create a Provider-Hosted app
  2. Create a Microsoft Azure web 
  3. Register the app in Office 365
  4. Publish the remote web to Microsoft Azure
  5. Publish an app to SharePoint Online
  6. Add a SharePoint app to a site
Step 1 - Create a Provider-Hosted app

1. Launch Visual Studio 2013 as administrator
2. In Visual Studio select File/New/Project
3. In the New Project dialog:
      a. Select Templates/Visual C#/Office/SharePoint/Apps
      b. Click App for SharePoint 2013
      c. Name the new project SPAzureApp and click OK


4. In the New App for SharePoint wizard:

      a. Enter the address of a SharePoint site to use for testing the app (NOTE: The targeted site must  
          be based on a Developer Site template)
      b. Select Provider-Hosted as the hosting model.
      c. Click Next.



     d. Select ASP.NET MVC Web Application.
     e. Click Next.

     f. Select the option labeled Use Microsoft Azure Access Control Service (for SharePoint cloud 
         apps).
     g. Click Finish.

     h. When prompted, log in using your Office 365 administrator credentials.
     i. Press F5 to begin debugging.
     j. When prompted, log in using your Office 365 administrator credentials.
     k. When prompted, click Trust it.
     l. Verify that the app home page shows and that it properly welcomes you by name.

You now have a new working Provider-Hosted app project.

Step 2 - Create a Microsoft Azure Web

1. Log into the Azure Management Portal as an administrator.
2. Click Web Sites.
3. Click New.
4. Enter the web app name like SPAzureWeb
5. Click Quick Create

You will have the Azure web running now.

Step 3 - Register the app in Office 365

1. Log into the Office 365 developer site as an administrator
2. From the developer site, navigate to /_layouts/15/appregnew.aspx.
3. Click Generate next to Client ID.
4. Click Generate next to Client Secret.
5. Enter SP Azure App as the Title.
6. Enter the App Domain for the Azure web site you created earlier (e.g., 
    spazureweb.azurewebsites.net)
7. Enter the Redirect URI as the reference for the Customers page (e.g. 
    https://spazureweb.azurewebsites.net).
8. Click Create.
9. Save the Client ID and Client Secret separately for later use.


Step 4 - Publish the remote web to Microsoft Azure
1. Log into the Azure Management Portal as an administrator.
2. Double click Web Sites you created like SPAZureWeb
3. Click Download the publish profile under Publish your app
4. Remember the file location like C:\Users\harryc\Downloads\SPAzureWeb.azurewebsites.net
5. In Visual Studio 2013 the SPAzureApp solution, right click SPAzureApp
6. Click Publish...

7. Click New and select the file from previous Step 4.4

8. Click Next
9. Enter the Client ID and Client Secret from Step 3

10. Click Finish
11. Click Deploy your web project

12. Click Publish

13. You should see the publish success mesage
2>Adding ACL's for path (SPAzureWeb)
2>Adding ACL's for path (SPAzureWeb)
2>Publish Succeeded.
2>Web App was published successfully http://spazureweb.azurewebsites.net/
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

Now the web app has been published to Azure.

Step 5 - Publish an app to SharePoint Online

1. Right click the SPAzureApp project and select Publish.
2. Click Package the App.
3. Change the URL used as entry point to https instead of default http

4. Click Finish.
5. Now remember the location of the app file named SPAzureApp.app

The following steps are optional and only necessary if you want the app to be published to app catalog so all site could use it.
6. Return to the Office 365 tenant and select Admin/SharePoint.
7. Click Apps/App Catalog.
 
8.  Select Create new app catalog site if you do not have created already
9.  Click OK.
10. Fill out the required information for the new app catalog site and click OK.
11. Once created, navigate to the new app catalog site.
12 In the app catalog site, click Apps for SharePoint.
13. Click New.
14. Browse to the app package you created earlier.
15. Add the app package to the Apps for SharePoint library.

Step 6 - Add a SharePoint app to a site

Option #1 - If you have already added the app to the app catalog 
1. Navigate to a site in your Office 365 tenancy.
2. Click Site Contents. (NOTE: If you are using the Developer site, it may have an older version of the app still installed from testing. You must remove the app from the site AND remove the entry from the  Apps in Testing  list or the new app will not install.)
3. Click Add an App.
4. Click From Your Organization.
5. Click the app installer.
6. When prompted, click Trust It.
7. Use the tile to launch the app.

Option #2 - If you have not already added the app to the app catalog and like to add the app directly to the site
1. Login to the site and click Apps in Testing
2. Click new app to deploy
3. Click upload

4. Identify the app file generated from Step 5.5

5. Click Deploy
6. When prompted, click Trust It.

Now you can click the App title to lunch the App.

This will be the complete steps to deploy a simple Provider-Hosted app to Microsoft Azure used for SharePoint Online site. We will continue to explain the deployment of Provider-Hosted app utilizing Azure AD and O365 API later.