In my previous blog I have explain about how to configure your on premise 2013 SharePoint for App modal deployments. In this blog I will write about how to create a provider hosted app and publish it on SharePoint. I will explain the steps consider SharePoint for Production environment.
Pre Requisite:
SharePoint 2013 is installed. Https web application is already created on port 443 (or any port for simplicity I am taking default 443 port in this article). SharePoint is configured to support App Modal for reference see:
Steps:
Step 1: To setup an app catalog for a web application
Step 2: Obtain Client Id and Secret from SharePoint
To obtain Client Id and Secret Navigate to
<AppCatalogURL>/_layouts/15/appregnew.aspx
The below page will open.
Generate Client ID, Generate Secret Id, and Title for your App, App Domain (this must be domain of IIS web site for your App Server) and Redirect URL: This must be default page URL of your App. Make sure to save this information somewhere as we will be needing this from time to time.
Step 3: Create High Trust for App
To work with Provider Hosted App we need to create a high trust between the App Server and SharePoint.
To Create the High Trust Copy the below PowerShell Command in PS1 file and run it with the on SharePoint Management Shell 2013
To create a high trust between servers we require a certificate It can be a self-signed certificate or a domain certificate.
Pass the Client ID which is generated in step 2.
param(
[Parameter(Mandatory)][String] $CertPath = $(throw "Usage: HighTrustConfig-ForSingleApp.ps1 -CertPath <full path to .cer file> -CertName <name of certificate> [-SPAppClientID <client ID of SharePoint app>] [-TokenIssuerFriendlyName <friendly name>]"),
[Parameter(Mandatory)][String] $CertName,
[Parameter(Mandatory)][String] $SPAppClientID,
[Parameter()][String] $TokenIssuerFriendlyName
)
# Stop if there's an error
$ErrorActionPreference = "Stop"
# Ensure friendly name is short enough
if ($TokenIssuerFriendlyName.Length -gt 50)
{
throw "-TokenIssuerFriendlyName must be unique name of no more than 50 characters."
}
# Get the certificate
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertPath)
# Make the certificate a trusted root authority in SharePoint
New-SPTrustedRootAuthority -Name $CertName -Certificate $certificate
# Get the GUID of the authentication realm
$realm = Get-SPAuthenticationRealm
# Must use the client ID as the specific issuer ID. Must be lower-case!
$specificIssuerId = New-Object System.String($SPAppClientID).ToLower()
# Create full issuer ID in the required format
$fullIssuerIdentifier = $specificIssuerId + '@' + $realm
# Create issuer name
if ($TokenIssuerFriendlyName.Length -ne 0)
$tokenIssuerName = $TokenIssuerFriendlyName
else
$tokenIssuerName = $specificIssuerId
# Register the token issuer
New-SPTrustedSecurityTokenIssuer -Name $tokenIssuerName -Certificate $certificate -RegisteredIssuerName $fullIssuerIdentifier
Step 4: Add Root Authority
In case you have generated a domain certificate or your self-signed certificate as root certificates than you need to add all those certificates also as TrustedRootauthority in Sharepoint to do that you need to run the below powerShell Commands.
[Parameter(Mandatory)][String] $CertName = $(throw "Usage: AddSPRootAuthority.ps1 -CertPath <full path to .cer file> –CertName <name of certificate>"),
[Parameter(Mandatory)][String] $CertPath
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertPath)
New-SPTrustedRootAuthority -Name $CertName -Certificate $cert
Step 5: Configure App Principal
You need to configure App Principal on SharePoint site on which you want to Install your App. To clarify this is not the Catalog url else it is Url of SharePoint Host web on which you want to use your app. To do this Run the following powershell commands
[Parameter(Mandatory)][String] $appDisplayName,
[Parameter(Mandatory)][String] $clientID,
[Parameter(Mandatory)][String] $targetSiteUrl
$targetSite = Get-SPSite $targetSiteUrl
$realm = Get-SPAuthenticationRealm -ServiceContext $targetSite
$fullAppPrincipalIdentifier = $clientID + '@' + $realm
Write-Host "Registering new app principal"
$registeredAppPrincipal = Register-SPAppPrincipal -NameIdentifier $fullAppPrincipalIdentifier -Site $targetSite.RootWeb -DisplayName $AppDisplayName
$registeredAppPrincipal | select * | Format-List
$registeredAppPrincipal | select * | Format-List | Out-File -FilePath "Output.txt"
Write-Host "Registration Completed"
Step 6: To create a high-trust app for SharePoint
References: http://msdn.microsoft.com/en-us/library/office/fp179901(v=office.15).aspx
Step 7: Publish and Deploy
1: Deploy the web application
To open the Publish your app page
In Solution Explorer, open the shortcut menu for the app for SharePoint project, and then choose Publish.
The Publish your app page appears.
To select or create a profile
In the Current profile list, choose a profile to import, or choose <New …> to create a profile.
.
If you choose <New …>, the Create publishing profile wizard appears.
To deploy your web app project
On the Publish your app page, choose the Deploy your web project button.
The Publish Web dialog box appears.
On the Connection and Settings tabs, fill in any missing values.
To change how the files for your app for SharePoint are published or if the app uses an external database, choose the Settings tab. See the section "Configuring the Settings Tab" in How to: Deploy a Web Project using On-Click Publishing in Visual St....
To review what items will change when the web app is deployed, choose the Start Preview button on the Preview tab.
Choose the Publish button to deploy the web app project.
Step 2: Package the App
On the Publish your app page, choose the Package the app button.
The Publish apps for Office and SharePoint wizard appears.
In the Where is your website hosted? text box, enter the URL of the website that will host the content files of your app for SharePoint.
You must specify an address that starts with the "https" prefix. See Why do my apps have to be SSL-secured?.
In the What is the app's client ID? text box, the client ID that you entered in the publishing profile should already appear.
If you’ve used a placeholder value for the client ID until this point, you must add an actual client ID now. This information is embedded in the .app package and enables your web content to communicate with SharePoint on the live site.
Choose the Finish button.
Visual Studio generates the files that are needed to publish your app for SharePoint and then opens the publish output folder. For information about how to install the app, see Install and manage apps for SharePoint 2013.
Step 3: Publish your app for SharePoint
References: http://msdn.microsoft.com/en-us/library/office/jj220044(v=office.15).aspx
Step 8: Using APP