<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>SharePoint bits</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/jesusfer/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/jesusfer/feed.xml</link>
    <description>A blog with SharePoint related stuff</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:05:43 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SharePoint 2013 Role claims augmentation</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2013-role-claims-augmentation</link>
      <pubDate>Mon, 25 Jan 2016 08:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2016/01/25/sharepoint-2013-role-claims-augmentation/</guid>
      <description><![CDATA[Say you have ADFS configured (or any trusted provider for that matter) in your web application and...]]></description>
      <content:encoded><![CDATA[<p>Say you have ADFS configured (or any trusted provider for that matter) in your web application and you use ADFS roles to grant permissions to the sites in it. When users log in everything works correctly but then an admin wants to check the permissions of a certain user. And then&hellip; why does SharePoint say that the user doesn't have permissions on the site?</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/2086.1.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/2086.1.png" alt="" border="0" /></a></p>
<p>And I know that my user a1@adfs has permissions because I have the role "ADFS test users" in my visitors group and I know that the user can access it the site without problems! And I even checked some days before and SharePoint showed that the user had permissions to the site.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/5025.2.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/5025.2.png" alt="" border="0" /></a></p>
<p>So, how come SharePoint is telling me now that the user doesn't have permissions?</p>
<p>&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 12pt">SharePoint's external token</span></p>
<p>&nbsp;</p>
<p>SharePoint stores in the content database a token of the user, per site collection, where it saves a set of claims that represent the user. This set of claims contains, among other things, what groups/roles the user is a member of. As you might be guessing now, when we check the permissions of a user, we use this set of claims to compute the permissions.&nbsp;</p>
<p>Other non-interactive operations like alerts, not only "Check permissions", use this token of the user when doing security trimming.</p>
<p>The external token has also a timestamp of when it was last updated. We don't want to have stale tokens in our databases, so we will update it from time to time. How often it is updated depends on the operation that forces the refresh.</p>
<p>In one of my previous posts (<a href="http://blogs.msdn.com/b/jesusfer/archive/2015/08/27/authentication-lifetime-settings.aspx">SharePoint 2013 authentication lifetime settings</a>) I explained how often we refresh this token (token-timeout) and how that value can be changed.</p>
<p>&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 12pt">How does SharePoint refresh the external token?</span></p>
<p>&nbsp;</p>
<p>At this point, you can guess that if we are not getting the expected results when we check the permissions of a user, then it means that the external token of the user doesn't have all of the user's groups/roles in it and that's why the dialog is showing less permissions than expected. But why is the external token missing the roles?</p>
<p>When SharePoint retrieves the token from the database and decides that it needs to update the token (the last token update is beyond the token timeout), it asks the local STS to build a new token of the user. When the web application uses Windows authentication, the local STS just needs to contact the AD domain where the user account resides and it gets all the information it needs from there, builds the new token and saves it in the content database. This is why when the web application uses Windows authentication, it just works. There is a scenario where it may not: the user was just added to a group right after the token was updated.</p>
<p>However, in our original scenario, we are using ADFS authentication, so when the local STS tries to get the information about the user, it just doesn't know where to look for it and then it can only build the minimal token it can with the little information he can get from the user. This means that the token will not contain any roles and thus it will make "Check permissions" fail to compute the correct permissions.</p>
<p>Does this mean that the external token will always be missing the roles? How come it sometimes work? As I said above, we are dealing here with non-interactive logons of the user. In the case of an interactive logon (i.e., the user is actually accessing the site), the <em>interactive</em> identity of the user holds all the claims of the user, and if the login happens to trigger a refresh of the token (by default, if the token is older than 60 minutes), then the token will be refreshed with this interactive identity and then it will contain all the claims as expected. From this point, "Check permissions" will work as expected until the token is refreshed again.</p>
<p>&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 12pt">But why?</span></p>
<p>&nbsp;</p>
<p>What the local STS actually does when building the token (either in a interactive or not logon) is the following:</p>
<ul>
<li>It gets all of the registered claim providers and keeps those providers that can do claim augmentation (<strong>SPClaimProvider.SupportsEntityInformation</strong> returns <strong>true</strong>).</li>
<li>For each of those providers that do augmentation, then calls their <strong>FillClaimsForEntity()</strong> method.</li>
<li>The providers will return a list of claims to add to the identity and the STS will aggregate them in the final token.</li>
</ul>
<p>The problem with SharePoint's default claim providers is that none support augmenting the claims of an trusted provider identity. If you think about it, it makes sense because there is no certain way to understand where the information of this user comes from, so it's impossible to know who to contact to get it when we are refreshing the token of the user.</p>
<p>These are the default claim providers in an out-of-the-box SharePoint farm:</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 10pt">SharePoint 2010</span></p>
<p><span style="font-family: 'courier new', courier">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SupportsEntityInformation</span></p>
<p><span style="font-family: 'courier new', courier">----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------------------------</span></p>
<p><span style="font-family: 'courier new', courier">System&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; True</span></p>
<p><span style="font-family: 'courier new', courier">AD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False</span></p>
<p><span style="font-family: 'courier new', courier">AllUsers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False</span></p>
<p><span style="font-family: 'courier new', courier">Forms&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 10pt">SharePoint 2013</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SupportsEntityInformation</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------------------------</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">System&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; True</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">AD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">AllUsers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;False</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">Forms&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False</span></p>
<p><span style="color: #000000;font-family: 'courier new', courier">User Profile Claim Provider&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; True</span></p>
<p>&nbsp;</p>
<p>As you can see, only System supports claims augmentation. In SharePoint 2013 we also have User Profile Claim Provider that supports claims augmentation, but it only works on Windows identities, so it cannot help with our problem.</p>
<p>&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 12pt">The solution</span></p>
<p>&nbsp;</p>
<p>In this case, the solution is to create a custom claim provider that will understand how our farm is built and will do the claims augmentation. The general idea of such a claim provider would be:</p>
<ul>
<li>When it gets the identity to augment, understand if it has to do the augmentation or not.</li>
<li>If it does, get the information from the user. This can be as simple as getting this information from AD with DirectoryServices or maybe do a LDAP query to whatever directory stores the information.</li>
<li>When it has the information from the user, build the role claims from it and return them to STS.</li>
</ul>
<p>I have created a sample Visual Studio project with a claim provider that does the above. You can find the code here: <a href="https://github.com/jesusfer/FedRolesCP">https://github.com/jesusfer/FedRolesCP</a></p>
<p>For the cases explained above, the custom claim provider can be the starting point for a more specific provider. The example can be directly used in an environment such as:</p>
<ul>
<li>The SharePoint farm and the users reside in the same forest.</li>
<li>The ADFS server is configured with Active Directoy as authentication and user backend.</li>
</ul>
<p>The master branch of the project is compatible with SharePoint 2013. However, there is a tag with a SharePoint 2010 compatible version.</p>
<p>Several of our customers have already implemented successfully a custom claim provider starting from this code to solve problems with alerts, when checking user's permissions and even with SharePoint 2013 Apps authentication. Nearly everywhere where trusted role identities are involved.</p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013 Automatically update the ADFS token signing certificate - Revisited</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2013-automatically-update-the-adfs-token-signing-certificate-revisited</link>
      <pubDate>Thu, 19 Nov 2015 12:55:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2015/11/19/sharepoint-2013-automatically-update-the-adfs-token-signing-certificate-revisited/</guid>
      <description><![CDATA[In my last post I wrote about a&nbsp;PowerShell script that can be used to automatically update the...]]></description>
      <content:encoded><![CDATA[<p>In my last post I wrote about a&nbsp;PowerShell script that can be used to automatically update the token signing certificate in the ADFS trusted providers.</p>
<p>This project aims to solve this problem by creating a custom timer job that will download the ADFS federation metadata and check if the primary token signing certificate has changed. If it has changed, then it'll udpate SharePoint with the new certificate.</p>
<p>The project currently includes:</p>
<ul>
<li>A custom timer job definition.</li>
<li>A custom admin page in Central Administration that allows an admin to select which providers to update.</li>
<li>Custom ULS logging.</li>
</ul>
<p>You can find the code in the following Github project: <a href="https://github.com/jesusfer/ADFSCertificateUpdater">https://github.com/jesusfer/ADFSCertificateUpdater</a></p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013 Automatically update the ADFS token signing certificate - Updated</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2013-automatically-update-the-adfs-token-signing-certificate</link>
      <pubDate>Fri, 06 Nov 2015 04:13:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2015/11/06/sharepoint-2013-automatically-update-the-adfs-token-signing-certificate/</guid>
      <description><![CDATA[The problem
&nbsp;
One of the caveats when using ADFS as authentication provider in SharePoint is...]]></description>
      <content:encoded><![CDATA[<h3 style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt">The problem</h3>
&nbsp;
<p lang="en-US" style="margin: 0in;font-family: Calibri;font-size: 11pt">One of the caveats when using ADFS as authentication provider in SharePoint is that out-of-the-box there is no way to automatically update the ADFS token signing certificate when it's changed in the ADFS server. Many times, the ADFS admins leave the ADFS certificate auto rollover enabled. This means that ADFS will automatically create a new self-signed certificate and will change the primary certificate some days before the current one expires. Unless the SharePoint admin knows when the certificate rollover will happen, which isn't usually the case, it will most probably render the ADFS authentication with SharePoint broken until the SharePoint admin realizes the certificate was changed and updates the certificate in the ADFS settings.</p>
&nbsp;
<h3 style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt">A workaround</h3>
&nbsp;
<p lang="en-US" style="margin: 0in;font-family: Calibri;font-size: 11pt">At the end of this post, you can find a PowerShell script that can be run in a scheduled task. What this function does is:</p>

<ol>
 	<li>
<div lang="en-US" style="margin-top: 0px;margin-bottom: 0px;vertical-align: middle"><span style="font-family: Calibri;font-size: 11pt;font-style: normal;font-weight: normal">Using the <a href="https://gallery.technet.microsoft.com/scriptcenter/AD-FS-Diagnostics-Module-8269de31">AD FS Diagnostics PowerShell module</a>, request a Security Token from the ADFS server in order to get the current primary signing certificate.</span></div></li>
 	<li>
<div lang="en-US" style="margin-top: 0px;margin-bottom: 0px;vertical-align: middle"><span style="font-family: Calibri;font-size: 11pt">If the current primary certificate is not already in the SharePoint trust store, it will add it to the store.</span></div></li>
 	<li>
<div lang="en-US" style="margin-top: 0px;margin-bottom: 0px;vertical-align: middle"><span style="font-family: Calibri;font-size: 11pt">Then, if the current primary certificate in ADFS is different from the current signing certificate in the ADFS login provider in SharePoint, it will update the provider to use this new certificate.</span></div></li>
</ol>
The script takes two arguments:
<ul>
 	<li>FederationServer: this is the host name of the ADFS server, for example, fs.contoso.com</li>
 	<li>TrustedProvider: this is the name of the AD FS login provider in SharePoint, something like "Contoso ADFS". The following PowerShell will output the names of the trusted providers configured in SharePoint: <code>Get-SPTrustedIdentityTokenIssuer | ft Name</code></li>
</ul>
&nbsp;
<p lang="en-US" style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt">Last thoughts</p>
&nbsp;
<p lang="en-US" style="margin: 0in;font-family: Calibri;font-size: 11pt">Even if you are not using the auto certificate rollover feature in ADFS and you manually update the token signing certificate, the above PowerShell can also help to update the certificate.</p>
<p lang="en-US" style="margin: 0in;font-family: Calibri;font-size: 11pt">Finally, the requested Security Token only includes the last certificate in the certificate chain. This means that, if the ADFS signing certificate is not self-signed, then only the last certificate in the chain will be imported into SharePoint. SharePoint documentation says that you need to import all the certificates in the chain. However, this should have been done when initially configuring the ADFS provider in SharePoint so it's not something you should need to care about when updating the certificate, unless you have changed the CA that issues the certificate.</p>
&nbsp;
<p lang="en-US" style="margin: 0in;font-family: Calibri;font-size: 11pt">Get the script from GitHub: <a href="https://github.com/jesusfer/sharepoint-scripts/blob/master/Update-AdfsSigningCertificate.ps1">Update-AdfsSigningCertificate.ps1</a></p>
&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013 Grant permissions via custom ADFS claims</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2013-grant-permissions-via-custom-adfs-claims</link>
      <pubDate>Tue, 29 Sep 2015 09:58:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2015/09/29/sharepoint-2013-grant-permissions-via-custom-adfs-claims/</guid>
      <description><![CDATA[In the times of classic authentication, you could only grant permissions to users by grouping them...]]></description>
      <content:encoded><![CDATA[<div class="WordSection1">
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="EN-US">In the times of classic authentication, you could only grant permissions to users by grouping them into Active Directory groups or by granting permissions directly to users. With claims authentication we can now virtually use any claim that the users have to grant permissions.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="EN-US">The high level view of this process would be:</span></p>
<ol>
<li><span style="text-indent: -18pt" lang="EN-US">Identify which claims the users have and which one you want to use.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">Build the claim value you will use to grant permissions.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">Add the claim to the item permissions.</span></li>
</ol>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 12pt">Identify the current claims</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">Depending on the authentication provider configured in the web application the users will have some claims when they log in. After login, SharePoint augments those claims with several claim providers which add more claims to the user identity. One of these claim providers is the User Profile application and this is why it makes sense to have a running User Profile Application to keep the user properties up to date.&nbsp;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="EN-US">You can use the following PowerShell to get the installed claim providers in the farm:</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">Get-<span class="SpellE">SPClaimProvider</span> | <span class="SpellE">ft</span> -auto <span class="SpellE"><span class="GramE">DisplayName,IsEnabled</span>,IsUsedByDefault,IsVisible</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span class="SpellE"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">DisplayName</span></span><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">IsEnabled</span> <span class="SpellE">IsUsedByDefault</span> <span class="SpellE">IsVisible</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">-----------<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>--------- --------------- ---------</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">System<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">Active Directory<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>False<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">All Users<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">Forms <span class="SpellE">Auth</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True<span>&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>False<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">User Profile Claim Provider<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">LDAPCP<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>True<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE">True</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">The way to check which claims a user has, would be to use a custom web part to show those claims based on the current user. This is an example of such a web part (<span class="SpellE">Helloitsliam.ClaimsViewerWebPart.wsp</span>, can't find the current link for download):</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span class="Apple-tab-span"> <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/7345.image001.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/7345.image001.png" alt="" border="0" /></a></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">In the example I'm going to use for this post, I want to be able to give permissions to sites using the Department the users have in Active Directory. My lab uses AD FS to authenticate the users.</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">If you check the screenshot above, you can see that there is no Department claim that we can use to grant permissions so we are going to have to add the claim there.</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span style="color: #5b9bd5;font-size: 12pt"><br />Adding a custom claim</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">This is the overview of the steps we need to do to make AD FS forward a new claim to SharePoint and make SharePoint use that claim when authenticating the user:</p>
<ol>
<li><span style="text-indent: -18pt" lang="EN-US">Check if AD FS supports the claim we want to use. If not, create a new Claim description.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">Modify the AD FS Relying Party to add the claim to the token sent to SharePoint.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">Modify the trust relationship in SharePoint to accept this new claim and use it in the Claims Identity.</span></li>
</ol>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><em><span style="font-size: 12.0pt;color: #5b9bd5" lang="EN-US">Adding a Claim description in AD FS</span></em></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">We open the AD FS Management console and go to AD FS -&gt; Service -&gt; Claim Descriptions. Here we can find the list of claims supported by AD FS. I don't see a Department claim, so we are going to have to add it.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/2867.image002.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/2867.image002.png" alt="" border="0" /></a></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">A new Claim description can be added directly via the console or with PowerShell. My preferred method is always PowerShell so we use the following command:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">Add-<span class="SpellE">AdfsClaimDescription</span> -Name Department -<span class="SpellE">ShortName</span> department -<span class="SpellE">ClaimType</span> <a href="http://custom-claims/department">http://custom-claims/department</a> -<span class="SpellE">IsAccepted</span> $true -<span class="SpellE">IsOffered</span> $true</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">You can find the documentation of this command <a href="https://technet.microsoft.com/en-us/library/dn479354(v=wps.630).aspx">here</a>.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">After this, we can see the claim in the list and use it in our relying party:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/0576.image003.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/0576.image003.png" alt="" border="0" /></a></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><em><span style="font-size: 12.0pt;color: #5b9bd5" lang="EN-US">Add the new claim to the Relying party</span></em></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">Just like any LDAP attribute, we need to modify the current Claim rules in the Relying party to pass this claim to SharePoint. Just open the current claim rules and add the new claim to the current rules. You will most probably have a "Send LDAP attributes as claims" so you can directly add the new claim there or add a new rule if you want.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/7536.image004.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/7536.image004.png" alt="" border="0" /></a></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">From now on, every new login will include the new claim.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><em><span style="font-size: 12.0pt;color: #5b9bd5" lang="EN-US">Add the claim to the SharePoint trust</span></em></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">Now that the security token sent by AD FS includes the new token, we need to make SharePoint aware of this new claim.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">When we set up AD FS in SharePoint, we create a Trusted Identity Token Issuer. In this issuer object, we define the claims accepted by SharePoint from it and define some mappings from the claim type to the internal claim type.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">So, what claim types are currently accepted by SharePoint? As usual, we use PowerShell for this:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">Get-<span class="SpellE">SPTrustedIdentityTokenIssuer</span> | % <span class="GramE">{ Write</span>-Host $_.Name; $_.<span class="SpellE">ClaimTypes</span> | <span class="SpellE">ft</span> -auto }</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">And this is the current output:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">ADFS UPN</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"><a href="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress">http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress</a></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"><a href="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn">http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn</a></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"><a href="http://schemas.microsoft.com/ws/2008/06/identity/claims/role">http://schemas.microsoft.com/ws/2008/06/identity/claims/role</a></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"><a href="http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid">http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid</a></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">To add the new claim type we do the following:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">ctype</span> = "<a href="http://custom-claims/department">http://custom-claims/department</a>"</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"># <span class="SpellE">First</span>, <span class="SpellE">we</span> <span class="SpellE">need</span> to define <span class="SpellE">the</span> new <span class="SpellE">encoding</span> <span class="SpellE">character</span> for <span class="SpellE">this</span> new <span class="SpellE">claim</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"># </span><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">Make sure that your character is not used in another encoding, it is above 500 (0x01F5) and not an uppercase or whitespace character.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">New-<span class="SpellE">SPClaimTypeEncoding</span> -<span class="SpellE">EncodingCharacter</span> ([Convert<span class="GramE">]::</span><span class="SpellE">ToChar</span>(501)) -<span class="SpellE">ClaimType</span> $<span class="SpellE">ctype</span> </span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US"># Add the mapping</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$ti = <span class="SpellE">Get-SPTrustedIdentityTokenIssuer</span> "ADFS UPN"</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">ti.ClaimTypes.Add</span>($<span class="SpellE">ctype</span>)</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">map</span> = New-<span class="SpellE">SPClaimTypeMapping</span> -<span class="SpellE">IncomingClaimType</span> $<span class="SpellE">ctype</span> -<span class="SpellE">IncomingClaimTypeDisplayName</span> "<span class="SpellE">Department</span>" &ndash;<span class="SpellE">SameAsIncoming</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span class="SpellE"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">Add-SPClaimTypeMapping</span></span><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"> &ndash;<span class="SpellE">Identity</span> $<span class="SpellE">map</span> &ndash;<span class="SpellE">TrustedIdentityTokenIssuer</span> $ti</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US"># Confirm the mapping works, the following should return an encoded claim.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="EN-US">(New-<span class="SpellE">SPClaimsPrincipal</span> -<span class="SpellE">TrustedIdentityTokenIssuer</span> "ADFS UPN" -<span class="SpellE">ClaimValue</span> "<span class="SpellE">Dept</span> 1" -<span class="SpellE">ClaimType</span> "<a href="http://custom-claims/department">http://custom-claims/department</a>").<span class="SpellE">ToEncodedString</span>()</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 54.0pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span class="SpellE"><span lang="X-NONE">From</span></span><span lang="X-NONE"> <span class="SpellE">now</span> <span class="SpellE">on</span>, SharePoint <span class="SpellE">accepts</span> <span class="SpellE">the</span> <span class="SpellE">incoming</span> <span class="SpellE">Department</span> <span class="SpellE">claim</span> <span class="SpellE">from</span> AD FS and <span class="SpellE">adds</span> <span class="SpellE">it</span> to <span class="SpellE">the</span> <span class="SpellE">claims</span> <span class="SpellE">identity</span> <span class="SpellE">that</span> <span class="SpellE">represents</span> <span class="SpellE">the</span> <span class="SpellE">logged</span> in <span class="SpellE">user</span>.</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span class="SpellE"><span lang="X-NONE">We</span></span><span lang="X-NONE"> <span class="SpellE">could</span> <span class="SpellE">even</span> <span class="SpellE">check</span> <span class="SpellE">the</span> <span class="SpellE">claims</span> <span class="SpellE">viewer</span> <span class="SpellE">webpart</span> <span class="SpellE">again</span> and <span class="SpellE">we</span> <span class="SpellE">will</span> <span class="SpellE">now</span> <span class="SpellE">see</span> <span class="SpellE">the</span> new <span class="SpellE">claim</span> in <span class="SpellE">the</span> <span class="SpellE">identity</span>:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4544.image005.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4544.image005.png" alt="" border="0" /></a></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span class="SpellE"><span style="font-size: 12.0pt;color: #5b9bd5" lang="X-NONE">Granting</span></span><span style="font-size: 12.0pt;color: #5b9bd5" lang="X-NONE"> <span class="SpellE">permissions</span> <span class="SpellE">using</span> <span class="SpellE">the</span> new <span class="SpellE">claim</span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span class="SpellE"><span lang="X-NONE">The</span></span><span lang="X-NONE"> <span class="SpellE">next</span> <span class="SpellE">step</span>, once <span class="SpellE">the</span> <span class="SpellE">claim</span> <span class="SpellE">we</span> <span class="SpellE">want</span> to use <span class="SpellE">is</span> <span class="SpellE">available</span>, <span class="SpellE">is</span> to <span class="SpellE">grant</span> <span class="SpellE">permission</span> <span class="SpellE">using</span> <span class="SpellE">this</span> <span class="SpellE">claim</span>. <span class="SpellE">Ideally</span>, <span class="SpellE">we</span> <span class="SpellE">would</span> <span class="SpellE">like</span> to <span class="SpellE">directly</span> <span class="SpellE">type</span> <span class="SpellE">the</span> <span class="SpellE">value</span> of <span class="SpellE">the</span> new <span class="SpellE">claim</span> in <span class="SpellE">People</span> <span class="SpellE">Picker</span> and <span class="SpellE">get</span> <span class="SpellE">it</span> <span class="SpellE">correctly</span> resolved <span class="SpellE">by</span> <span class="SpellE">People</span> <span class="SpellE">Picker</span>. <span class="SpellE">Unfortunately</span>, SharePoint <span class="SpellE">does</span> <span class="SpellE">not</span> do <span class="SpellE">this</span> <span class="SpellE">out</span> of <span class="SpellE">the</span> box and <span class="SpellE">we</span> <span class="SpellE">will</span> <span class="SpellE">need</span> to use a <span class="SpellE">custom</span> <span class="SpellE">claim</span> <span class="SpellE">provider</span> <span class="SpellE">if</span> <span class="SpellE">we</span> <span class="SpellE">want</span> <span class="SpellE">this</span> <span class="SpellE">feature</span>.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span class="SpellE"><span lang="X-NONE">Out</span></span><span lang="X-NONE"> of <span class="SpellE">the</span> box <span class="SpellE">we</span> can use PowerShell to <span class="SpellE">grant</span> <span class="SpellE">permissions</span>.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$web = <span class="SpellE">Get-SPWeb</span> <a href="https://team.2013.net">https://team.2013.net</a></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"># <span class="SpellE">This</span> <span class="SpellE">will</span> use <span class="SpellE">the</span> <span class="SpellE">Claim</span> <span class="SpellE">Provider</span> <span class="SpellE">used</span> <span class="SpellE">by</span> <span class="SpellE">the</span> <span class="SpellE">TrustedIdentityTokenIssuer</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">claim</span> = New-<span class="SpellE">SPClaimsPrincipal</span> -<span class="SpellE">TrustedIdentityTokenIssuer</span> "ADFS UPN" -<span class="SpellE">ClaimValue</span> "<span class="SpellE">Dept</span> 1" -<span class="SpellE">ClaimType</span> "<a href="http://custom-claims/department">http://custom-claims/department</a>"</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-family: Consolas;font-size: 10pt">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">## <span class="SpellE">If</span> <span class="SpellE">there</span> <span class="SpellE">is</span> no <span class="SpellE">Claim</span> <span class="SpellE">Provider</span> <span class="SpellE">that</span> can <span class="SpellE">resolve</span> <span class="SpellE">the</span> <span class="SpellE">claim</span>, New-<span class="SpellE">SPUser</span> <span class="SpellE">will</span> <span class="SpellE">fail</span> <span class="SpellE">but</span> <span class="SpellE">we</span> can <span class="SpellE">directly</span> <span class="SpellE">grant</span> <span class="SpellE">permissions</span> <span class="SpellE">using</span> <span class="SpellE">RoleAssignments</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"># <span class="SpellE">Example</span>: <span class="SpellE">directly</span> <span class="SpellE">grant</span> <span class="SpellE">Read</span> <span class="SpellE">permissions</span> <span class="SpellE">on</span> <span class="SpellE">the</span> web</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">[<span class="SpellE">Microsoft.SharePoint.SPRoleAssignment</span>] $<span class="SpellE">roleAssignment</span> = New-<span class="SpellE">Object</span> <span class="SpellE">Microsoft.SharePoint.SPRoleAssignment</span>($<span class="SpellE">claim.ToEncodedString</span>(), "", "<span class="SpellE">Department</span> 1", "")</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$roleAssignment.RoleDefinitionBindings.Add($web.RoleDefinitions["Read"])</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">web.RoleAssignments.Add</span>($<span class="SpellE">roleAssignment</span>)</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE"># <span class="SpellE">Example</span>: <span class="SpellE">add</span> <span class="SpellE">the</span> <span class="SpellE">claim</span> to a SharePoint <span class="SpellE">group</span></span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">group</span> = $<span class="SpellE">web.Groups</span>["<span class="SpellE">members</span>"]</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span style="font-size: 10.0pt;font-family: Consolas" lang="X-NONE">$<span class="SpellE">group.AddUser</span>($<span class="SpellE">claim.ToEncodedString</span>(), "", "<span class="SpellE">Department</span> 1", "")</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span class="SpellE"><span lang="X-NONE">However</span></span><span lang="X-NONE">, <span class="SpellE">the</span> <span class="SpellE">best</span> and more <span class="SpellE">user</span> <span class="SpellE">friendly</span> <span class="SpellE">approach</span> <span class="SpellE">is</span> to use a <span class="SpellE">custom</span> <span class="SpellE">claim</span> <span class="SpellE">provider</span> <span class="SpellE">that</span> can be <span class="SpellE">configured</span> to <span class="SpellE">resolve</span> <span class="SpellE">custom</span> <span class="SpellE">claims</span>. <a href="https://ldapcp.codeplex.com/">LDAPCP</a> <span class="SpellE">is</span> <span class="SpellE">truly</span> <span class="SpellE">awesome</span>.</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal">With it, we just have to configure a new claim mapping&hellip;</p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4466.image006.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4466.image006.png" alt="" border="0" /></a></p>
<p class="MsoNormal" style="margin-bottom: .0001pt;line-height: normal"><span lang="X-NONE">&nbsp;</span><span lang="X-NONE">&hellip;</span><span lang="EN-US">and People Picker will work like a charm:</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal"><span lang="X-NONE">&nbsp;</span></p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: .0001pt;margin-left: 27.0pt;line-height: normal">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/8547.image007.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/8547.image007.png" alt="" border="0" /></a></p>
<p class="MsoNormal">&nbsp;</p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2010 and 2013 FedAuth cookie encryption</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2010-and-2013-fedauth-cookie-encryption</link>
      <pubDate>Mon, 14 Sep 2015 04:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2015/09/14/sharepoint-2010-and-2013-fedauth-cookie-encryption/</guid>
      <description><![CDATA[The issue
&nbsp;
If you are using SharePoint with AD FS, you may know how these two products...]]></description>
      <content:encoded><![CDATA[<div class="WordSection1">
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 14.0pt;color: #2e75b5" lang="EN-US">The issue</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">If you are using SharePoint with AD FS, you may know how these two products interact. </span><span class="SpellE"><span>The</span></span><span> <span class="SpellE">following</span> <span class="SpellE">summarizes</span> <span class="SpellE">the</span> <span class="SpellE">login</span> <span class="SpellE">process</span>:</span></p>
<ol>
<li><span style="text-indent: -18pt" lang="EN-US">When the user is not logged in, SharePoint will redirect the user to the AD FS login page.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">The user enters his credentials.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">AD FS validates the credentials and creates a Security Token with the user's claims.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">AD FS makes the user's browser or client POST this token to SharePoint's /_trust endpoint.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">SharePoint validates the digital signature on the token and stores the token in the Distributed Cache.</span></li>
<li><span style="text-indent: -18pt" lang="EN-US">SharePoint creates a FedAuth cookie with some information about the session. The contents of the cookie are Base 64 encoded and sent to the client. Inside the cookie we can find the user identity claim, the scope, expiration and a couple more things.</span></li>
</ol>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: 0cm;margin-left: 27.0pt;line-height: normal">For example, this is the content of a FedAuth cookie in my lab.</p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: 0cm;margin-left: 27.0pt;line-height: normal">&nbsp;</p>
<p class="MsoNormal" style="margin-top: 0cm;margin-right: 0cm;margin-bottom: 0cm;margin-left: 27.0pt;line-height: normal">&nbsp;<span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">&lt;?</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515" lang="EN-US">xml</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: red" lang="EN-US">version</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">=</span><span style="font-size: 9.5pt;font-family: Consolas" lang="EN-US">"</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">1.0</span><span style="font-size: 9.5pt;font-family: Consolas" lang="EN-US">" </span><span style="font-size: 9.5pt;font-family: Consolas;color: red" lang="EN-US">encoding</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">=</span><span style="font-size: 9.5pt;font-family: Consolas" lang="EN-US">"</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">utf-8</span><span style="font-size: 9.5pt;font-family: Consolas" lang="EN-US">"</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">?&gt;</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">&lt;</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515" lang="EN-US">SP</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">&gt;</span><span style="font-size: 9.5pt;font-family: Consolas;background: #ccffcc" lang="EN-US">05.t|adfs email|a1@email.local</span><span style="font-size: 9.5pt;font-family: Consolas" lang="EN-US">,05.t|adfs email|a1@email.local,<span class="GramE">130866957906607856,True</span>,[signature],https://adfs.2013.sps/</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">&lt;/</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515" lang="EN-US">SP</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue" lang="EN-US">&gt;</span></p>
<p class="MsoNormal" style="line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">Depending on the configuration of the AD FS provider in SharePoint, one of the claims in the AD FS token will be used as identity claim in SharePoint. This claims will be used to uniquely identify the user in SharePoint and thus it's very important to choose a property of the user that's unique. Most organizations choose the e-mail address or the User-Principal-Name.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">Some organizations may want to use a different identity claim like the social security number or another fiscal information of the user. These organizations may consider this kind of information sensitive and they even may want to protect this information.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">Since anybody can decode Base64, anybody can see the contents of the FedAuth cookie. In the one above, I have highlighted the identity claim. One way to protect this information would be to encrypt the value of the cookie.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 14.0pt;color: #2e75b5" lang="EN-US">The solution</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">SharePoint does not offer cookie encryption out of the box so if you want to encrypt this value, custom code needs to be<span>&nbsp;</span>created.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">One possible solution could be a custom HttpModule that will encrypt the cookie when set by SharePoint and decrypt it when SharePoint receives it.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">The custom HttpModule would attach to:</span></p>
<ul>
<li><span lang="EN-US">BeginRequest: to decrypt any FedAuth cookie that may come with the client's request.</span></li>
<li><span style="text-indent: -18pt">EndRequest: to encrypt any FedAuth cookie that may be set by SharePoint to the client.</span></li>
</ul>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">How should we encrypt the value?</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">I'm my opinion, a symmetric algorithm would be ideal over an asymetric. Symmetric algorithms are usually faster and don't require a key pair to work, just a password. How to choose a proper password and salt would be the interesting part. It has to be a password/salt combination that doesn't change between application pool recycles and both need to be the same in every web server. As an example, the code below uses a password and salt stored in the web.config of the application.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 12.0pt;color: #5b9bd5" lang="EN-US">The code</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">The code consists of two parts: the custom HttpModule and a utility class to handle the encryption. This utility class I got from the following link: </span><span><a href="http://www.superstarcoders.com/blogs/posts/symmetric-encryption-in-c-sharp.aspx"><span lang="EN-US">http://www.superstarcoders.com/blogs/posts/symmetric-encryption-in-c-sharp.aspx</span></a></span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">This should be compiled to a DLL. The easiest way to install it would be to copy the DLL into the bin folder of the web application and then add the module with IIS Manager.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><em><span style="font-size: 12.0pt;color: #5b9bd5" lang="EN-US">HttpModule</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.Collections.Generic;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.Linq;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.Security.Cryptography;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.Text;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.Web;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.Web.Configuration;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">namespace</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> jesusfer.SharePoint.FedAuthEncryptionModule</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;summary&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">///</span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"> This is a HttpModule that will encrypt the value of a certain cookie when it's set by the server and will decrypt it when sent by the client.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// </span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">///</span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"> This is helpful in cases when the FedAuth cookie includes an identity claim that can be considered sensitive.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;/summary&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public class </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">FedAuthEncryptionModule</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> : </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">IHttpModule</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> m_CookieName = </span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515;background: white" lang="EN-US">"FedAuth"</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// If true, unencrypted FedAuth cookies will still be allowed.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// If false, unecrypted FedAuth cookies will be removed, which will force SPS to ask the user to authenticate again.</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private bool</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> m_AllowUnencryptedCookies;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private bool</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> m_Enabled;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> m_Password;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> m_Salt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">/*</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* These are the expected settings keys in the web.config:</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* </span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* &lt;configuration&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* ...</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*<span>&nbsp;&nbsp;&nbsp; </span>&lt;appSettings&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;add key="FedAuthEncryptionEnabled" value="true"/&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;add key="FedAuthEncryptionPassword" value="FedAuthEncryptionPassword"/&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;add key="FedAuthEncryptionSalt" value="FedAuthEncryptionSalt"/&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*<span>&nbsp;&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;</span>&lt;add key="FedAuthEncryptionAllowUnencryptedCookies" value="true"/&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>*<span>&nbsp;&nbsp;&nbsp; </span>&lt;/appSettings&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* ...</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* &lt;/configuration&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>* */</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">String</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> ModuleName</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">get</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> { </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">return </span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515;background: white" lang="EN-US">"CookieEncryptModule"</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">; }</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;</span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public void</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> Dispose() { }</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public void</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> Init(</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpApplication</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> application)</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// Read configuration</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_Enabled = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">bool</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Parse(</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">WebConfigurationManager</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.AppSettings[</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515;background: white" lang="EN-US">"FedAuthEncryptionEnabled"</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">]);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_AllowUnencryptedCookies = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">bool</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Parse(</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">WebConfigurationManager</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.AppSettings[</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515;background: white" lang="EN-US">"FedAuthEncryptionAllowUnencryptedCookies"</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">]);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_Password = </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">WebConfigurationManager</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.AppSettings[</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515;background: white" lang="EN-US">"FedAuthEncryptionPassword"</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">];</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>m_Salt = </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">WebConfigurationManager</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.AppSettings[</span><span style="font-size: 9.5pt;font-family: Consolas;color: #a31515;background: white" lang="EN-US">"FedAuthEncryptionSalt"</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">];</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// Attach to the BeginRequest event so that we can check if the cookie is encrypted to decrypt it</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>application.BeginRequest += </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">EventHandler</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">this</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Application_BeginRequest);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// Attach to the EndRequest event so that we can encrypt the coookie when it's set by SharePoint</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>application.EndRequest += </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">EventHandler</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">this</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Application_EndRequest);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;summary&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">///</span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"> This method will encrypt the cookie when it's set by SharePoint</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;/summary&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;param name="sender"&gt;&lt;/param&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;param name="e"&gt;&lt;/param&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private void</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> Application_EndRequest(</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">object</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> sender, </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">EventArgs</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> e)</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpApplication</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> application = (</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpApplication</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">)sender;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpContext</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> context = application.Context;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">if</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (m_Enabled &amp;&amp; context.Response.Cookies.AllKeys.Contains(m_CookieName))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">try</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// Try encrypting the cookie value and setting it as the new value</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> plain = context.Response.Cookies[m_CookieName].Value;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> encrypted = </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CipherUtility</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Encrypt&lt;</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">AesManaged</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&gt;(plain, m_Password, m_Salt);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>context.Response.Cookies[m_CookieName].Value = encrypted;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white">}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white">catch</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white">// Do <span class="SpellE">nothing</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;summary&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">///</span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"> This method will decrypt the cookie when sent by the client</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;/summary&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;param name="sender"&gt;&lt;/param&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">/// &lt;param name="e"&gt;&lt;/param&gt;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">private void</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> Application_BeginRequest(</span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">object</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> sender, </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">EventArgs</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> e)</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpApplication</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> application = (</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpApplication</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">)sender;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">HttpContext</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> context = application.Context;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// m_enabled can be added as a condition here too, but that will break any FedAuth cookie that is encrypted and still valid</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp; </span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">if</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (m_Enabled &amp;&amp; context.Request.Cookies.AllKeys.Contains(m_CookieName))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white">try</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// Try decrypting the cookie value and setting it as the new value</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> encryped = context.Request.Cookies[m_CookieName].Value;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> decrypted = </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CipherUtility</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Decrypt&lt;</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">AesManaged</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&gt;(encryped, m_Password, m_Salt);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>context.Request.Cookies[m_CookieName].Value = decrypted;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">catch</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US">// We can choose to remove the cookie if decryption failed</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">if</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (!m_AllowUnencryptedCookies)</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>context.Request.Cookies.Remove(m_CookieName);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><em><span style="font-size: 12.0pt;color: #5b9bd5" lang="EN-US">Utility Class</span></em></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE"><span class="GramE">System.Collections.Generic</span></span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> System.IO;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE">System.Linq</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE"><span class="GramE">System.Security.Cryptography</span></span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE">System.Text</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">namespace</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE"><span class="GramE">jesusfer.SharePoint.FedAuthEncryptionModule</span></span></span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: gray;background: white" lang="EN-US">///</span><span style="font-size: 9.5pt;font-family: Consolas;color: green;background: white" lang="EN-US"> This class was copied from </span><span style="font-size: 9.5pt;font-family: Consolas" lang="EN-US"><a href="http://www.superstarcoders.com/blogs/posts/symmetric-encryption-in-c-sharp.aspx"><span style="color: green;background: white">http://www.superstarcoders.com/blogs/posts/symmetric-encryption-in-c-sharp.aspx</span></a></span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public class </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CipherUtility</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public static string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> Encrypt&lt;T<span class="GramE">&gt;(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> value, </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> password, </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> salt) </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">where</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> T : </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">SymmetricAlgorithm</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">, </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">()</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">DeriveBytes</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE">rgb</span> = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Rfc2898<span class="GramE">DeriveBytes<span style="color: black">(</span></span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">password, </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Encoding</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Unicode.GetBytes</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(salt));</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">SymmetricAlgorithm</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> algorithm = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="GramE">T(</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">byte</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">[</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">] <span class="SpellE">rgbKey</span> = <span class="SpellE">rgb.GetBytes</span>(<span class="SpellE">algorithm.KeySize</span> &gt;&gt; 3);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">byte</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">[</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">] <span class="SpellE">rgbIV</span> = <span class="SpellE">rgb.GetBytes</span>(<span class="SpellE">algorithm.BlockSize</span> &gt;&gt; 3);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">ICryptoTransform</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> transform = <span class="SpellE"><span class="GramE">algorithm.CreateEncryptor</span></span>(<span class="SpellE">rgbKey</span>, <span class="SpellE">rgbIV</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (</span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">MemoryStream</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> buffer = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span class="SpellE"><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">MemoryStream</span></span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (</span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CryptoStream</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> stream = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span class="SpellE"><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CryptoStream</span></span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">buffer, transform, </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CryptoStreamMode</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Write</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;</span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (</span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">StreamWriter</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> writer = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span class="SpellE"><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">StreamWriter</span></span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">stream, </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Encoding</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Unicode</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="SpellE"><span class="GramE">writer.Write</span></span>(value);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">return </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Convert</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.ToBase64String(<span class="SpellE"><span class="GramE">buffer.ToArray</span></span>());</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">public static string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> Decrypt&lt;T<span class="GramE">&gt;(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> text, </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> password, </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">string</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> salt) </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">where</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> T : </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">SymmetricAlgorithm</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">, </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">()</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">DeriveBytes</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="SpellE">rgb</span> = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Rfc2898<span class="GramE">DeriveBytes<span style="color: black">(</span></span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">password, </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Encoding</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Unicode.GetBytes</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(salt));</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">SymmetricAlgorithm</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> algorithm = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> <span class="GramE">T(</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">byte</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">[</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">] <span class="SpellE">rgbKey</span> = <span class="SpellE">rgb.GetBytes</span>(<span class="SpellE">algorithm.KeySize</span> &gt;&gt; 3);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">byte</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">[</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">] <span class="SpellE">rgbIV</span> = <span class="SpellE">rgb.GetBytes</span>(<span class="SpellE">algorithm.BlockSize</span> &gt;&gt; 3);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">ICryptoTransform</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> transform = <span class="SpellE"><span class="GramE">algorithm.CreateDecryptor</span></span>(<span class="SpellE">rgbKey</span>, <span class="SpellE">rgbIV</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (</span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">MemoryStream</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> buffer = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">MemoryStream</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Convert</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.FromBase64String(text)))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (</span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CryptoStream</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> stream = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span class="SpellE"><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CryptoStream</span></span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">buffer, transform, </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">CryptoStreamMode</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Read</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">using</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> (</span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">StreamReader</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"> reader = </span><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white" lang="EN-US">new </span><span class="SpellE"><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">StreamReader</span></span></span><span class="GramE"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">(</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">stream, </span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: #2b91af;background: white" lang="EN-US">Encoding</span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">.Unicode</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US">))</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white" lang="EN-US"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white">{</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span class="SpellE"><span style="font-size: 9.5pt;font-family: Consolas;color: blue;background: white">return</span></span><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"> <span class="SpellE"><span class="GramE">reader.ReadToEnd</span></span>();</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white"><span>&nbsp;&nbsp;&nbsp; </span>}</span></p>
<p class="MsoNormal" style="margin-bottom: 0cm;line-height: normal"><span style="font-size: 9.5pt;font-family: Consolas;color: black;background: white">}</span></p>
<p class="MsoNormal">&nbsp;</p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013 authentication lifetime settings</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2013-authentication-lifetime-settings</link>
      <pubDate>Thu, 27 Aug 2015 10:05:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2015/08/27/sharepoint-2013-authentication-lifetime-settings/</guid>
      <description><![CDATA[When SharePoint 2013 authenticates a user, the Security Token Service creates a security token with...]]></description>
      <content:encoded><![CDATA[<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">When SharePoint 2013 authenticates a user, the Security Token Service creates a security token with the user's identity and several other claims. This token is then added to the Distributed Logon Token Cache so that it can be checked later to confirm that the user is authenticated.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">When built, the token gets a lifetime that depends on the authentication provider used by the user to authenticate. For Windows and Forms (FBA) authentication, the lifetime is a fixed amount of time that is set on the Security Token Service configuration. For trusted providers like AD FS, the lifetime depends on the validity of the security token POSTed to SharePoint's /_trust/ endpoint.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">This lifetime has a direct impact in how often the user will need to authenticate. When the user makes a request, the token in the cache is checked and if it is expired, then the user needs to authenticate again.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in" lang="en-US"><span style="font-family: Calibri;font-size: 11pt">As explained above, the lifetime can be configured in the STS for Windows and Forms authentication. The current values can be reviewed with </span><span style="color: blue;font-family: 'Lucida Console';font-size: 9pt">Get-SPSecurityTokenServiceConfig</span><span style="font-family: Calibri;font-size: 11pt">.</span></p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt" lang="en-US">WindowsTokenLifetime</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">This lifetime applies to user sessions authenticated with Windows Integrated Authentication (NTLM/Kerberos).</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The default value is 10 hours.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">Get-SPSecurityTokenServiceConfig</span></p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">WindowsTokenLifetime </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">New-TimeSpan </span><span style="background: white;color: navy">-Hours </span><span style="background: white;color: purple">10</span></p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">Update()<br /></span></p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt" lang="en-US">FormsTokenLifetime</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The same as above but applies to Forms/FBA authentication sessions.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The default value is also 10 hours.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">Get-SPSecurityTokenServiceConfig</span></p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">FormsTokenLifetime </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">New-TimeSpan </span><span style="background: white;color: navy">-Hours </span><span style="background: white;color: purple">10</span></p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">Update()<br /></span></p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt" lang="en-US">LogonTokenCacheExpirationWindow</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The lifetime of a token in the cache is deducted the window value when checking if it is expired. This means that the real lifetime of the token will be less than expected. The following diagram can be helpful to understand when a token is valid and the roles the lifetime and window play in the expiration.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4274.ExpirationWindow.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4274.ExpirationWindow.png" alt="" border="0" /></a></p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The default value for the expiration window is 10 minutes.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">Get-SPSecurityTokenServiceConfig</span></p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">LogonTokenCacheExpirationWindow </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">New-TimeSpan </span><span style="background: white;color: navy">-Minutes </span><span style="background: white;color: purple">10</span></p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">Update()<br /></span></p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt" lang="en-US">CookieLifetime</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">When using FBA or a trusted provider, SharePoint will set a cookie on the client called FedAuth. I'll not go into the details of what's inside the FedAuth cookie. Of course, the FedAuth cookie will have by default a certain lifetime. Session cookies can be configured too making the cookie invalid after the closing the browser and then bypassing the value in this settings.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The default value is 5 days.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">Get-SPSecurityTokenServiceConfig</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">CookieLifetime </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">New-TimeSpan </span><span style="background: white;color: navy">-Days </span><span style="background: white;color: purple">5</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$sts</span><span style="background: white;color: #979797">.</span><span style="background: white">Update()</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">So, if we are using a trusted provider, for example, AD FS, how do we control how long the token will be valid? It will depend on how you can configure the STS that creates the token but if it is AD FS then you can set this in the Relying Party configuration.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt" lang="en-US">ADFS RP's TokenLifetime</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">This setting will change for how long the security token created by AD FS is valid. SharePoint will use this lifetime and set its security token lifetime to the same value.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">The default value is 60 minutes (which appears as 0 if the setting has not been changed in the RP).</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">You can check the current settings with:</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt"><span style="color: blue">Get-AdfsRelyingPartyTrust </span><span style="color: #979797">| </span><span style="color: blue">ft </span><span style="color: navy">-auto </span><span style="color: blueviolet">Name</span><span style="color: #979797">,</span><span style="color: blueviolet">TokenLifetime</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">And to change the value for a RP:</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.75in;font-family: 'Lucida Console';font-size: 9pt"><span style="color: blue">Set-AdfsRelyingPartyTrust </span><span style="color: navy">-TargetName </span><span style="color: darkred">"SharePoint 2013" </span><span style="color: navy">-TokenLifetime </span><span style="color: purple">30</span></p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">These are the main settings related to session lifetimes when dealing with user authentication. There are other values for applications and services but are kind of exotic and you won't usually need to change those.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">There is one extra setting that is interesting to have in mind although it does not affect the authentication of a user.</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in;color: #5b9bd5;font-family: Calibri;font-size: 12pt" lang="en-US">Token-timeout</p>
<p style="margin: 0in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">SharePoint stores in the content database a token of the user that includes some claims like group memberships. This token needs to be refreshed from time to time to make features like "Check permissions" and other some security trimmed features work as expected.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">These tokens will be refreshed at least every 24 hours. Some operations that require having a fresher token, like "Check permissions", will refresh the token at least every 60 minutes.</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in" lang="en-US"><span style="background: white;font-family: 'Lucida Console';font-size: 9pt">TokenTimeout</span><span style="font-family: Calibri;font-size: 11pt"> will change the default 24 hours timeout to a greater or smaller amount. If the value is still greater than 60 minutes, some operations will still use 60 minutes as minimum.</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: Calibri;font-size: 11pt" lang="en-US">&nbsp;</p>
<p style="margin: 0in 0in 0in 0.375in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$cs </span><span style="background: white;color: #979797">= [</span><span style="background: white;color: teal">Microsoft.SharePoint.Administration.SPWebService</span><span style="background: white;color: #979797">]::</span><span style="background: white">ContentService</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: 'Lucida Console';font-size: 9pt" lang="en-US"><span style="background: white;color: orangered">$cs</span><span style="background: white;color: #979797">.</span><span style="background: white">TokenTimeout </span><span style="background: white;color: #979797">= </span><span style="background: white;color: blue">New-TimeSpan </span><span style="background: white;color: navy">-Minutes </span><span style="background: white;color: purple">5</span></p>
<p style="margin: 0in 0in 0in 0.375in;font-family: 'Lucida Console';font-size: 9pt"><span style="background: white;color: orangered">$cs</span><span style="background: white;color: #979797">.</span><span style="background: white">Update()</span></p>]]></content:encoded>
    </item>
    <item>
      <title>SharePoint 2013 Apps and AAM</title>
      <link>https://docs.microsoft.com/archive/blogs/jesusfer/sharepoint-2013-apps-and-aams</link>
      <pubDate>Mon, 04 May 2015 09:41:00 GMT</pubDate>
      <dc:creator><![CDATA[Jesus Fernandez]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/jesusfer/2015/05/04/sharepoint-2013-apps-and-aams/</guid>
      <description><![CDATA[After the installation of the March 2013 PU, new options to assign Alternate Access Mappings for...]]></description>
      <content:encoded><![CDATA[<p>After the installation of the March 2013 PU, new options to assign Alternate Access Mappings for Apps were made available. The update allowed SharePoint admins to add alternate URLs for SharePoint hosted Apps.</p>
<p>This new feature can only be managed via PowerShell:</p>
<ul>
<li>New-SPWebApplicationAppDomain</li>
<li>Get-SPWebApplicationAppDomain</li>
<li>Remove-SPWebApplicationAppDomain</li>
</ul>
<h2>How does it work?</h2>
<p>&nbsp;Let&rsquo;s suppose you already have a web application working and you are using some apps and these apps use an app web. This means that the app web URL will be something similar to:</p>
<p>&lt;app prefix&gt; - &lt;app id&gt;.&lt;app domain&gt;</p>
<p>Say that your SharePoint farm was being used only in your company&rsquo;s network with an internal URL but now you want to publish it via a reverse proxy. To do this, you are extending the current web application to a new Zone so you are adding a new public URL to the web application. In RTM, there was no way to configure SharePoint to use several URLs for your Apps which meant that you needed to use a real public App domain.</p>
<p>Now, it is possible to have AAMs for Apps!</p>
<p>My test web application uses <span style="color: #3366ff">http://2013.test.local</span> as the public URL in the Default zone. I have configured the app domain as test-apps.local and I have followed <a href="https://technet.microsoft.com/en-us/library/fp161236.aspx">Configure an environment for apps for SharePoint (SharePoint 2013)</a> to configure my farm.</p>
<p>Right now, if I access my test App the URL it uses is the following:</p>
<p><span style="color: #3366ff">http://app-f28aaf39627eed.test-apps.local/AppWithWeb/Pages/Default.aspx</span></p>
<p>Since this domain uses an internal TLD it won&rsquo;t be possible to access the App from outside the corporate network.</p>
<p>What if you use a reverse proxy that rewrites the URL? Then, you might be able to access the App&rsquo;s web but other things like Javascript object model might not work correctly.</p>
<h2>How do you add a new App domain?</h2>
<p>You can find the steps in the following Technet article: <a href="https://technet.microsoft.com/en-us/library/dn144963.aspx">Enable apps in AAM or host-header environments for SharePoint 2013</a></p>
<p>Going back to our test lab, I now want to publish my web application so that my site will now be also available with the URL <span style="color: #3366ff">https://2013.test.net</span>. I will use a reverse proxy to do the SSL termination here. I won&rsquo;t explain how to do the SSL termination but this are my new AAM collection for this web application after extending:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/5415.1.AAMs.png"><img style="margin-right: auto;margin-left: auto" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/5415.1.AAMs.png" alt="" border="0" /></a></p>
<p>After extending the web application and configuring my reverse proxy to proxy all requests from <span style="color: #3366ff">https://2012.test.net</span> to <span style="color: #3366ff">http://2013.test.net:81</span>, I got access to the site with the new URL. However, when I click in the App, I still get redirected to <span style="color: #3366ff">http://app-f28aaf39627eed.test-apps.local</span>.</p>
<p>We need to do two things to have a different URL:</p>
<ol>
<li>Create the URL/Zone mappings.</li>
<li>Enable the mapping feature in the ContentService.</li>
</ol>
<h4>1. Creating the mappings</h4>
<p>First, we need to use the New-SPWebApplicationAppDomain cmdlet to assign the URLs. We will be adding the URL for the Default zone and then add the URL for the new Extranet zone.</p>
<p><span style="font-family: courier new,courier">New-SPWebApplicationAppDomain -AppDomain test-apps.local -WebApplication http://2013.test.local</span></p>
<p><span style="font-family: courier new,courier">New-SPWebApplicationAppDomain -AppDomain test-apps.net -WebApplication http://2013.test.local -Zone Extranet -SecureSocketsLayer -Port 82</span></p>
<p>If we now do a Get-SPWebApplicationappDomain we&rsquo;d get both URLs:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/6064.2.PS.png"><img style="margin-right: auto;margin-left: auto" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/6064.2.PS.png" alt="" border="0" /></a></p>
<p>Why did I choose to use SSL and port 82 on the new URL?</p>
<ol>
<li>I chose to use SSL because I want every communication in the apps to be secure, no OAuth token flying around unencrypted, but mainly, because I want the URL of the App web to use HTTPS so that it matches my web application URL that it&rsquo;s also using HTTPS.</li>
<li>Then, I chose to use port 82 because I&rsquo;m using SSL. If we don&rsquo;t specify the port, then it&rsquo;ll use the same port that the extended web application uses. In my case it would be 81. However, I&rsquo;m doing SSL offloading so my IIS binding in the Extranet zone is actually HTTP/81. Since I don&rsquo;t want SSL termination for my Apps, I need a HTTPS binding and for this I need another port to bind to.</li>
</ol>
<p>This also means that if you use a different port that the zone&rsquo;s, this cmdlet will actually add the binding to the IIS site. And if you are using SSL, then you&rsquo;ll need to configure the encryption certificate manually in the IIS bindings. Of course, the certificate should be a wildcard certificate for *.test-apps.net (or whatever new domain you are using for this zone)</p>
<p>After running the cmdlet, these are the bindings in my web server:</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/3162.3.IIS.png"><img style="margin-right: auto;margin-left: auto" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/3162.3.IIS.png" alt="" border="0" /></a></p>
<h4>&nbsp;2. Enabling the feature</h4>
<p>This step is as simple as running these PowerShell cmdlets:</p>
<p><span style="font-family: courier new,courier">$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService</span></p>
<p><span style="font-family: courier new,courier">$contentService.SupportMultipleAppDomains = $true</span></p>
<p><span style="font-family: courier new,courier">$contentService.Update()</span></p>
<p>&nbsp;After adding the mappings and enabling the feature, you need to do an IISReset in all your web servers.</p>
<h2>Aftermath</h2>
<p>After this configuration, now I can access my web application via my reverse proxy and when I open my App, the URL it now uses is the expected one and Javascript CSOM works flawlessly!</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4452.4.App.png"><img style="margin-right: auto;margin-left: auto" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/70/94/4452.4.App.png" alt="" border="0" /></a></p>
<h2>Some limitations worth mentioning</h2>
<ul>
<li>The zone you are adding an app domain to must exist and the web application must be extended to it.</li>
<li>You can share app domains between web applications, but the web applications must use the same application pool identity, zone and authentication provider.</li>
<li>If you use SSL in the app domain, then you must use a different port from the web application SSL port. Mainly because you need to have two different certificates, however, you might be able to use separate IPs for different certificates although I haven&rsquo;t tested this.</li>
</ul>]]></content:encoded>
    </item>
  </channel>
</rss>