<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>The Metaverse</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/metaverse/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/metaverse/feed.xml</link>
    <description>And all things related</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:23:26 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Query LDAP</title>
      <link>https://docs.microsoft.com/archive/blogs/metaverse/query-ldap</link>
      <pubDate>Tue, 14 Nov 2017 15:34:06 GMT</pubDate>
      <dc:creator><![CDATA[Jeff McMullen]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/metaverse/?p=75</guid>
      <description><![CDATA[Here is an example of how to query a secure LDAP service while using a certificate for...]]></description>
      <content:encoded><![CDATA[Here is an example of how to query a secure LDAP service while using a certificate for authentication.  This example utilizes a previous blog for importing the certificate:  <a href="https://blogs.msdn.microsoft.com/metaverse/2017/11/09/capturing-a-pki-certificate/">https://blogs.msdn.microsoft.com/metaverse/2017/11/09/capturing-a-pki-certificate/</a>

char[] commaExcape = new char[] { ',' };
char quotestring = '"';
string accountName = "JDUser";
string url = "server.fqdn:636";
string attrs = "uid,givenname,cn,ou";
string[] attrset = attrs.Split(commaExcape);

X509SecurityToken certtoken = GetSecurityToken("a1b2c3");
X509Certificate2 cert = new X509Certificate2(certtoken.Certificate);
LdapConnection ldap = new LdapConnection(url);
ldap.SessionOptions.SecureSocketLayer = true;
ldap.SessionOptions.ProtocolVersion = 3;
ldap.AuthType = AuthType.Basic;
ldap.ClientCertificates.Add(cert);
ldap.Bind();
SearchRequest request = new SearchRequest("c=us", "uid=" + accountName, SearchScope.Subtree, attrset);
DirectoryResponse response = ldap.SendRequest(request);
try
{
SearchResultEntry entry = ((SearchResultEntry)((new ArrayList((ReadOnlyCollectionBase)(((SearchResponse)(response)).Entries)))[0]));
Hashtable hashtable = new Hashtable();
foreach(DictionaryEntry keyval in entry.Attributes)
{
ArrayList value = (new ArrayList((CollectionBase)(keyval.Value)));
var key = System.Text.Encoding.Default.GetString((byte[])value[0]).Replace(quotestring.ToString(), "");
hashtable.Add(keyval, key);
}
}
catch (ArgumentOutOfRangeException)
{

throw;
}]]></content:encoded>
    </item>
    <item>
      <title>Quering JSON with Certificate</title>
      <link>https://docs.microsoft.com/archive/blogs/metaverse/quering-json-with-certificate</link>
      <pubDate>Tue, 14 Nov 2017 14:24:39 GMT</pubDate>
      <dc:creator><![CDATA[Jeff McMullen]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/metaverse/?p=45</guid>
      <description><![CDATA[I recently had a requirement to query an application that requires certificate authentication and...]]></description>
      <content:encoded><![CDATA[I recently had a requirement to query an application that requires certificate authentication and replies with JSON.<span style="float: none;background-color: transparent;color: #333333;cursor: text;font-family: Georgia,'Times New Roman','Bitstream Charter',Times,serif;font-size: 16px;font-style: normal;font-variant: normal;font-weight: 400;letter-spacing: normal;line-height: 24px;text-align: left;text-decoration: none;text-indent: 0px">  This example utilizes a previous blog for importing the certificate:  </span><a href="https://blogs.msdn.microsoft.com/metaverse/2017/11/09/capturing-a-pki-certificate/">https://blogs.msdn.microsoft.com/metaverse/2017/11/09/capturing-a-pki-certificate/</a>

X509SecurityToken certtoken = GetSecurityToken("a1b2c3");
X509Certificate2 cert = new X509Certificate2(certtoken.Certificate);
string accountName = "JDUser";
string url = "https://server.fqdn/rest/" + accountName;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.ContentType = "application/json";
request.ClientCertificates.Add(cert);
request.PreAuthenticate = true;
try
{
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
string responseContents = new StreamReader(responseStream).ReadToEnd();
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
object xmlresponse = JsonConvert.Deserialize&lt;dynamic&gt;(responseContents);
Dictionary&lt;string, object&gt; keyval = new Dictionary&lt;string, object&gt;();
keyval = (new Dictionary&lt;string, object&gt;((Dictionary&lt;string, object&gt;)(xmlresponse)));
Hashtable hashtable = new Hashtable();
foreach(KeyValuePair&lt;string,object&gt; kvset in keyval)
{
hashtable.Add(kvset.Key, kvset.Value);
}
}
catch (WebException)
{
// handle as you see fit.
}

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Capturing a PKI Certificate</title>
      <link>https://docs.microsoft.com/archive/blogs/metaverse/capturing-a-pki-certificate</link>
      <pubDate>Thu, 09 Nov 2017 13:43:06 GMT</pubDate>
      <dc:creator><![CDATA[Jeff McMullen]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/metaverse/?p=65</guid>
      <description><![CDATA[I found it was easiest to use a certificate token when accessing systems using a certificate.  This...]]></description>
      <content:encoded><![CDATA[I found it was easiest to use a certificate token when accessing systems using a certificate.  This is the method I use to accomplish the task querying based on the certificate thumbprint (the thumbprint ensures that I get correct certificate):
<pre><code>public X509SecurityToken GetSecurityToken(string certThumb)
 {
 X509SecurityToken securityToken = null;
 X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
 store.Open(OpenFlags.ReadOnly);
 try
 {
 X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, certThumb, false);
 X509Certificate2 cert;
 if(certs.Count == 1)
 {
 cert = certs[0];
 securityToken = new X509SecurityToken(cert);
 }
 else
 {
 securityToken = null;
 }
 }
 catch (Exception)
 {
 throw;
 }
 finally
 {
 if(store != null)
 {
 store.Close();
 }
 }
 return securityToken;
 }</code></pre>]]></content:encoded>
    </item>
    <item>
      <title>In the beginning</title>
      <link>https://docs.microsoft.com/archive/blogs/metaverse/in-the-beginning</link>
      <pubDate>Sun, 05 Nov 2017 13:20:49 GMT</pubDate>
      <dc:creator><![CDATA[Jeff McMullen]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/metaverse/?p=35</guid>
      <description><![CDATA[In the beginning there was the Metaverse, and the Metaverse was good.]]></description>
      <content:encoded><![CDATA[In the beginning there was the Metaverse, and the Metaverse was good.]]></content:encoded>
    </item>
  </channel>
</rss>