IT tutorials
 
Technology
 

Sharepoint 2013 : SharePoint App Security - Establishing app identity by using S2S trusts (part 3) - Developing provider-hosted apps by using S2S trusts

2/7/2014 8:44:05 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Developing provider-hosted apps by using S2S trusts

Before you begin to develop a provider-hosted app with a S2S trust, you should first complete the following steps.

  1. Create a .cer certificate file containing a public/private key pair.

  2. Use the .cer file to register a trusted security token issuer.

  3. Register an app principal with a client ID to help track app identity.

  4. Export the private key to a password-protected .pfx file.

  5. Make the .pfx file accessible on the server running the remote web.

After you have completed these steps, it is relatively simple to create a new provider-hosted app with Visual Studio 2012 and configure it to use an S2S trust. The first step is to update the app manifest with the client ID of an app principal that has already been registered.

<AppPrincipal>
<RemoteWebApplication ClientId="22222222-2222-2222-2222-222222222222" />
</AppPrincipal>

The next step is to update the web.config file of the remote web with four appSettings variables that track the IDs of the trusted security-token issuer and the app principal as well as the file path and password required to extract the private key from the .pfx file at run time. Note that these four appSettings variables are used by Microsoft-supplied code in the TokenHelper class. The information in these four variables is used each time the TokenHelper class creates an S2S access token.

<appSettings>
<add key="ClientId" value="22222222-2222-2222-2222-222222222222" />
<add key="ClientSigningCertificatePath" value="C:\Certs\appserver.wingtip.com.pfx" />
<add key="ClientSigningCertificatePassword" value="Password1" />
<add key="IssuerId" value="11111111-1111-1111-1111-111111111111" />
</appSettings>

At this point, you have seen all the steps required to configure an S2S trust. All that’s left to do is to write the code to create access tokens and to pass them to the SharePoint host environment in the Authentication header. The code in Example 5 demonstrates how to create an S2S access token by calling the GetS2SAccessTokenWithWindowsIdentity method of the TokenHelper class. After you have created an S2S access token string, you can add it as an Authorization header by using the exact same code as you would have in an app which uses OAuth.

Example 5. Creating an S2S access token

string hostWebUrl = Request.QueryString["SPHostUrl"];
Uri hostWebUri = new Uri(hostWebUrl);
WindowsIdentity currentUser = Request.LogonUserIdentity;

string accessTokenString =
TokenHelper.GetS2SAccessTokenWithWindowsIdentity(hostWebUri, currentUser);

// prepare HttpWebRequest to execute REST API call
HttpWebRequest request1 =
(HttpWebRequest)HttpWebRequest.Create(hostWebUrl.ToString() + "/_api/Web/
title");

// add access token string as Authorization header
request1.Headers.Add("Authorization", "Bearer " + accessTokenString);

// execute REST API call and inspect response
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
StreamReader reader1 = new StreamReader(response1.GetResponseStream());
XDocument doc1 = XDocument.Load(reader1);
string SiteTitle = doc1.Root.Value;

Calling TrustAllCertificates

While you are working in a development environment, it is common to use test certificates as opposed to production-grade certificates. The TokenHelper class provides a static method named TrustAllCertificates which can be called if you need to relax the rules used in the certificate verification process.

TokenHelper.TrustAllCertificates();

A call to TrustAllCertificates can be helpful to get things working in a development environment where you are using test certificates. However, any calls to TrustAllCertificates should be removed before your code.

 
Others
 
- Sharepoint 2013 : SharePoint App Security - Establishing app identity by using S2S trusts (part 2) - Configuring an S2S trust
- Sharepoint 2013 : SharePoint App Security - Establishing app identity by using S2S trusts (part 1) - Architecture of an S2S trust
- Sharepoint 2013 : SharePoint App Security - Establishing app identity by using OAuth (part 3) - Developing with OAuth - Working with access tokens
- Sharepoint 2013 : SharePoint App Security - Establishing app identity by using OAuth (part 2) - Developing with OAuth - Programming with the TokenHelper class
- Sharepoint 2013 : SharePoint App Security - Establishing app identity by using OAuth (part 1) - Understanding app principals
- Sharepoint 2013 : SharePoint App Security - Managing app permissions
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Clear Previous Entries
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Loop Through the Secondary Data Source , Populate the Repeating Table
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Create a Namespace Variable, Access the Secondary Data Source
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Create a Changed Event Method
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us