Thursday, February 27, 2020

Creating Provider hosted app (sharepoint online) with local hosted IIS

The Pre-requires are as follows.
1. Office 365 Subscription
2. Visual Studio 2015 (Professional/Community/Enterprise Edition)
With the pre-requisites ready, let us start with step by step
1. Login to the Office 365 and Create a Developer Site.
clip_image002
2. Login to the INETMGR and Create the Local IIS Sites.
clip_image004
3. Click on “Add WebSite”
clip_image006
4. Add an Entry on the Hosts File. The Host File can be found in the path “c:\Windows\System32\Drivers\etc\”
5. The entry is as follows.
a. 127.0.0.1 Office365PHA
6. We need to Create a Self-Signed Certificate and Bind the Certificate to the newly created Web Site.
7. To Create a self-signed certificate, this time, we are going to use PowerShell Script with the –DNSName.
The Script is as
New-SelfSignedCertificate -DnsName Office365PHA -CertStoreLocation cert:\LocalMachine\My
8. Let us open the PowerShell window as Administrator.
9. Enter the above mentioned Script.
clip_image008
10. Once, the certificate got created, go to IIS and Server Certificates. We should be able to see the newly created certificate.
clip_image010
11. Double Click and Copy to File.
clip_image012
12. Copy the CER file to any location.
clip_image014
clip_image016
clip_image018
clip_image020
clip_image022
clip_image024
13. With this, let us open the Visual Studio to Create the APP Project.
clip_image026
14. Select the App Type and enter the O365 URL.
clip_image028
15. Enter the Credential.
clip_image030
16. Select the Target Version of SharePoint.
clip_image032
17. Select the Project Type.
clip_image034
18. Select the Authentication Settings for the Low Trust.
clip_image036
19. On Click of Finish, the Solution will get created. The Solution will looks like below.
clip_image038
20. Now, Go to the APPREGNEW.aspx and register the Client ID and Client Secret ID. https://sppalsmvp.sharepoint.com/sites/DeveloperSite/_layouts/15/appregnew.aspx
clip_image040
21. Once, got created, copy the clientid and client Secret ID to a notepad.
clip_image042
22. Now, let us go back to the IIS and the Certificates. Go to the location where we stored the Certificate exported.
clip_image044
23. Right Click the Cer file. Click on Install Certificate.
clip_image046
24. Follow the below Wizards.
clip_image048
clip_image050
clip_image052
clip_image054
clip_image056
25. Now, Open the IIS and Select the WebSite which we created on the Earlier Steps.
26. Enable the Directory Browsing.
clip_image058
27. Right Click and Select Edit Bindings.
clip_image060
28. Add a Binding.
clip_image061
clip_image063
29. Now, launch the URLs, http://Office365PHA and https://Office365PHA and make sure that there is no exception. Though we have not provisioned the APP, but still we are making sure that the IIS does not have any issues.
30. Let us go back to the Visual Studio and update the AppManifest.xml.
31. The Updated XML will look like below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 <?xml version="1.0" encoding="utf-8" ?>
 <!--Created:cb85b80c-f585-40ff-8bfc-12ff4d0e34a9-->
 <App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest"
      Name="Office365PHAOnPremAPP"
      ProductID="{cf118bb0-a286-4727-809b-0c15cb2bbe40}"
      Version="1.0.0.0"
      SharePointMinVersion="16.0.0.0"
 >
   <Properties>
     <Title>Office365.PHA.OnPrem.APP</Title>
     <StartPage>~remoteAppUrl/Pages/Default.aspx?{StandardTokens}</StartPage>
   </Properties>
  
   <AppPrincipal>
     <RemoteWebApplication ClientId="21bd3e55-507c-4f1a-bf63-d17022a74e8a" />
   </AppPrincipal>
  
   <AppPermissionRequests AllowAppOnlyPolicy="false">
     <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
   </AppPermissionRequests>
    
 </App>
  
32. Update the Web.Config of the APP Web Project with the new ClientID and Client secret
clip_image065
33. Now, we are done. We need to publish the APP Web into the Local IIS. For that, follow the below steps.
34. Select the APPWeb and Click on Properties.
clip_image067
35. On the Web Tab, select the Local IIS and give the Redirect URI.
clip_image069
36. Click on “Create Virtual Directory”
37. Virtual Directory Got Created.
clip_image071
38. To Confirm, go to IIS and verify the Folder Structure.
39. In our case, it got created properly.
clip_image073
40. Now, we need to Publish the APP Project. For that, right click on the APPWeb and Click Publish. Note: Purposely, we are selecting the APPWeb, instead of the APP. Let me tell you in the below section, why we are doing this.
clip_image075
41. Click on Custom
42. Give the Profile Name and Click OK.
clip_image077
43. On the Below Screen, don’t give anything. Simply Close.
clip_image079
44. Save the Changes.
clip_image081
45. Now, Come back to the APP Project and Click Publish.
clip_image083
46. We will see the Profile which we created in the earlier step. Otherwise, the profile will not get created here. That’s why, I asked you to create the profile using the APPWeb Project and use the Profile in APP Project.
47. Click on Edit Profile and Enter the Client ID and the Client Secret properly.
clip_image085
clip_image087
48. Now, the Warning near to Edit will be gone.
clip_image089
49. Click on “Package the APP” Button and Enter the URL
clip_image091
50. We will get the Publish Success message.
clip_image093
51. Go to App Catalog Site. Refer HERE for further information regarding App Catalog
52. Upload the APP file into the App Catalog “Apps for SharePoint” List.
clip_image095
clip_image097
53. Now, come back to our Developer Site and go to Site Contents.
54. Click on “ADD an APP”
clip_image099
55. Select the APP
clip_image101
56. Trust the APP
clip_image103
57. This will take few minutes to Add the app.
58. Launch the APP
clip_image105
59. We will be seeing the Title of the SP Site.
clip_image107
60. Now, let us put a break point on your Source Code and attach the process with W3WP Process.
clip_image109
61. We can see the Debugger stops as shown below.
clip_image111

Creating Provider hosted app (sharepoint online) with local hosted IIS

The Pre-requires are as follows. 1. Office 365 Subscription 2. Visual Studio 2015 (Professional/Community/Enterprise Edition) With t...