Created
August 30, 2013 15:22
-
-
Save primaryobjects/6390975 to your computer and use it in GitHub Desktop.
Loading a Windows Identity Foundation thumbprint key with a custom ConfurationBasedIsserNameRegistry class. If you have hidden control characters in the thumbprint key, this will filter them out, allowing the cert to be accepted by WIF and SSO.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<issuerNameRegistry type="RelyingParty1.CustomIssuerNameRegistry, RelyingParty1"> | |
<trustedIssuers> | |
<add thumbprint="abcdefghijklmnopqrstuvwxyz1234567890abcd" name="optional name" /> | |
</trustedIssuers> | |
</issuerNameRegistry> | |
using System.IdentityModel.Tokens; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
using System.Xml; | |
namespace RelyingParty1 | |
{ | |
public class CustomIssuerNameRegistry : ConfigurationBasedIssuerNameRegistry | |
{ | |
public override void LoadCustomConfiguration(XmlNodeList customConfiguration) | |
{ | |
if (customConfiguration != null && customConfiguration.Count > 0) | |
{ | |
for (int i = 0; i < customConfiguration.Count; i++) | |
{ | |
var nd = customConfiguration.Item(0); | |
foreach (var add in nd.ChildNodes.Cast<XmlNode>().Where(e => !(e is XmlComment))) | |
{ | |
var thumbprint = add.Attributes.Cast<XmlNode>().FirstOrDefault(e => e.Name == "thumbprint"); | |
if (thumbprint != null) | |
{ | |
var rgx = new Regex("[^a-zA-Z0-9 -]"); | |
thumbprint.Value = rgx.Replace(thumbprint.Value, ""); | |
} | |
} | |
} | |
} | |
base.LoadCustomConfiguration(customConfiguration); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment