Introduction

This is a quick look at On Premise SharePoint 2013 environments. I decided to write this article because I knew the complexity of this PHA Configuration. Before jumping in to the PHA configuration, it’s worthwhile to quickly recap what are Provider Hosted Apps.

Provider Host App:

The provider Host App is hosted outside of SharePoint. The provider-hosted high trust app model is a powerful tool which should be utilized when the situation either demands custom managed code or when a low-trust solution does not suffice or SharePoint Host app does not do. It has its own infrastructure and the Provider is responsible for keeping it running. They allow you to use Server Side code and use the .NET CSOM (not the Microsoft.SharePoint.dll.)

host

Image Source.

Why Provider Host App?

Before you develop a provider Host App you may need to do some prerequisites,

For SharePoint you must have the following service applications provisioned and started:

High Trust Certificates:

A high-trust Certificate is a provider-hosted SharePoint App that uses the digital certificates to establish trust between the remote web application and SharePoint.

This is the link to create a certificate in IIS.

Here I would like to give a PowerShell code to create the self-signed certificate (.pfx file)

Note

In the folder that you saved the .cer and .pfx file in SharePoint server, be sure that the App pool identity for the following IIS Apps have Read rights to the C:\Certs folder.

icon

PowerShell Code;

Copy the below Code and save it as a Makecertificate.ps1

Then run the below cmd in PowerShell,

C:\powershells\Makecertificate.ps1-Domain apps.gowtham.com – OutputDir C:\Certificates -$Password Password1

PowershellCode:

  1. PARAM(
  2. [Parameter(Mandatory=$true, HelpMessage="Enter the uri for the domain (e.g. www.contoso.com).")][string]$Domain,
  3. [Parameter(Mandatory=$true, HelpMessage="Enter the full path where the certificates will be created.")][string]$OutputDir,
  4. [Parameter(Mandatory=$true, HelpMessage="Enter the password for the certificate.")][string]$Password
  5. )
  6. if (-not $outputDir.EndsWith('\'))
  7. {
  8. $outputDir += "\"
  9. }
  10. $makecert = "C:\Program Files\Microsoft Office Servers\15.0\Tools\makecert.exe"
  11. $certmgr = "C:\Program Files\Microsoft Office Servers\15.0\Tools\certmgr.exe"
  12. New-Item $outputDir -ItemType Directory -Force -Confirm:$false | Out-Null
  13. $pubCert = $outputDir + $domain + ".cer"
  14. $privateCert = $outputDir + $domain + ".pfx"
  15. $output = & $makecert -r -pe -n "CN=$domain" -b 01/01/2013 -e 01/01/2023 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sy 12 -sp "Microsoft RSA SChannel Cryptographic Provider" $pubCert
  16. $output = & $certmgr /add $pubCert /s /r localMachine root
  17. $publicCertificate = Get-PfxCertificate -FilePath $pubCert
  18. $publicCertificateThumbprint = $publicCertificate.Thumbprint
  19. Get-ChildItem cert:\\localmachine\my | Where-Object {$_.Thumbprint -eq $publicCertificateThumbprint} | ForEach-Object {
  20. $privateCertificateByteArray = $_.Export("PFX", $password)
  21. [System.IO.File]::WriteAllBytes($privateCert, $privateCertificateByteArray)
  22. }

Next Article: How to create IIS website and register the certificate to IIS website.