<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Leandro Boffi</title>
	<atom:link href="http://leandrob.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://leandrob.com</link>
	<description>Cloud, Identity, Mobility and Software Architecture.</description>
	<lastBuildDate>Fri, 03 May 2013 14:11:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Kidozen is alive!</title>
		<link>http://leandrob.com/2013/05/kidozen-is-alive/</link>
		<comments>http://leandrob.com/2013/05/kidozen-is-alive/#comments</comments>
		<pubDate>Fri, 03 May 2013 14:11:38 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Personal Experiences]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[kidozen]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://leandrob.com/?p=320</guid>
		<description><![CDATA[During the last year I worked almost exclusively on this. Kidozen, the world&#8217;s best cloud-based platform for building mobile applications with enterprise capabilities. Now, after a very successful private beta period we are announcing public availability. I&#8217;ll go deeper on what kidozen is and why is the world&#8217;s best cloud-based enterprise mobility platform, but I&#8217;d like to start [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.kidozen.com" target="_blank"><img class="alignright" style="float: right; margin-left: 10px;" alt="" src="https://identity.kidozen.com/Content/logoBlackMedium.png" width="105" height="105" /></a></p>
<p>During the last year I worked almost exclusively on this. Kidozen, the world&#8217;s best cloud-based platform for building mobile applications with enterprise capabilities.</p>
<p>Now, after a very successful private beta period we are announcing public availability. I&#8217;ll go deeper on what kidozen is and why is the world&#8217;s best cloud-based enterprise mobility platform, but I&#8217;d like to start talking about the experience of building this amazing product.</p>
<p>First of all I have to say that this is the kind of product in which I always wanted to work on. Why? Well, first because Kidozen is a platform for developers: APIs, SDKs, services and tools that developers will use, and second because is cloud-based and cloud computing is one of my favorite topics. Also, as you can imagine, build a whole cloud-based platform requires a lot of engineering work which was very interesting and enriching to do.</p>
<p>Kidozen&#8217;s core was built using <a title="Node.js" href="http://nodejs.com" target="_blank">Node.js</a> and a bunch of cloud services, so you can imagine how &#8220;cloud&#8221; is it&#8217;s spirit. We built the whole platform from scratch, it took a lot of effort and it could only have been done by a talented team like the Tellago Studios team. At this point I want to thank to the whole team: <a title="Gustavo" href="http://machadogj.com/" target="_blank">Gustavo</a>, <a title="Silvio" href="http://silviomassari.wordpress.com/" target="_blank">Silvio</a>, <a title="Christian" href="http://www.linkedin.com/in/christiancarnero" target="_blank">Christian</a>, <a title="Soledad" href="http://solepano.blogspot.com.ar/" target="_blank">Soledad</a>, <a title="Jose" href="http://joseoncode.com/" target="_blank">Jose</a> (that is not here anymore but devoted a lot of effort to the project and put in place many of the cornerstones of it) and <a title="Jesus" href="http://jrodthoughts.com/" target="_blank">Jesus</a> (the man with the vision) for the tremendous talent, the passion, the work over nights and basically for let me share with them this amazing experience that was building Kidozen.</p>
<h2>What is Kidozen?</h2>
<p>Imagine that you are a company that needs to build mobile applications for your employees or your customers. You will need to resolve things like data storage, logging, notifications, configuration etc. You also will need to resolve how to secure your data, maybe using your company directory credentials, Active Directory for example,  outside of the boundaries of your company or your Google Apps account. And what about distribute those apps? and manage them?. Well, Kidozen is here to solve all those problems for you.</p>
<p>Now, I&#8217;ve said that Kidozen is the world&#8217;s best cloud-based platform for doing enterprise mobility, why? because Kidozen not only provides data storage, push notifications, messaging, sms, email, configuration, logging, queues and many other backend services in a simple and secure way, it also provides an standard way of build, manage and distribute you company mobile applications.</p>
<p>We give you an app-centric model in which you have all those services isolated and ready to use with a single line of code, in a secure way using your company credentials (Active Directory) or web providers like Google, Yahoo, Facebook, etc&#8230;</p>
<p><span style="font-size: 13px; line-height: 19px;">We also provide a marketplace for your company that allows you to centralize the distribution of your applications, a management portal where you can create, manage, configure and publish your applications and SDKs for all the popular mobile platforms: Windows 8, iOS, Android and we also have a JavaScript SDK and hosting for HTML5 applications.</span></p>
<p>Why is the best one for developers? let me say it in this way, this is all the code you need to authenticate your Android users against your company AD, outside of your LAN:</p>
<pre class="co">kido.Authenticate(<span>"John Smith"</span>, <span>"P@ssw0rd!"</span>, authCallback);</pre>
<p>And this is all the code you need, to authenticate against your partner AD in the same application:</p>
<pre class="co">kido.Authenticate(<span>"Partner AD"</span>, <span>"John Smith"</span>, <span>"P@ssw0rd!"</span>, authCallback);</pre>
<p>Or this is all the code you need to send push notifications trough all your iPhones or iPads:</p>
<pre class="co"><b>id</b> notification = [<b>kido</b> pushNotifications];
[<b>notification</b> pushNotification:<span>@"Kidozen Rocks!"</span> InChannel:<span>@"kidoChannel"</span>];</pre>
<p>Did you get that? It is really simple but at the same time powerful.</p>
<p>Why is the best one for architects? Because it provides a simple, unified and standard way of building all you company applications, the final result is more maintainable and standardized applications.</p>
<p>Why is the best one for managers? Because now, with Kidozen, you can apply all your workforce in to build feature-rich business applications without having to spend time in to solve technical problems.</p>
<p>So that is Kidozen, our way of democratize enterprise mobile applications development. <a title="Give it a try!" href="http://www.kidozen.com" target="_blank">Give it a try!</a></p>
<h2>Next steps</h2>
<p>We are already working on the next version of Kidozen, expanding one of our key features &#8220;Line of Business APIs&#8221;, with this feature you will be able of integrate your on-premise services with your mobile applications in a secure way, with a single line of code.</p>
<p>If you want more information about kidozen don&#8217;t hesitate in to<a title="contact us!" href="mailto:lean@kidozen.com" target="_blank"> contact us</a>!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2013/05/kidozen-is-alive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADFS WS-Trust client for Node.js</title>
		<link>http://leandrob.com/2012/08/adfs-ws-trust-client-for-node-js/</link>
		<comments>http://leandrob.com/2012/08/adfs-ws-trust-client-for-node-js/#comments</comments>
		<pubDate>Thu, 23 Aug 2012 17:22:50 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[ADFS]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Node.js Modules]]></category>

		<guid isPermaLink="false">http://leandrob.com/?p=314</guid>
		<description><![CDATA[Joining two of my favorite topics, Node.js and Identity Federation I’ve created a very simple and minimalist WS-Trust client for Node.js, this module allows you to request a security token from ADFS using WS-Trust protocol. If you want to know how this works you can see the detailed explanation here. Also you can find the [...]]]></description>
				<content:encoded><![CDATA[<p>Joining two of my favorite topics, Node.js and Identity Federation I’ve created a very simple and minimalist WS-Trust client for Node.js, this module allows you to request a security token from ADFS using WS-Trust protocol.</p>
<p>If you want to know how this works you can see the detailed explanation <a href="http://leandrob.com/2012/02/request-a-token-from-adfs-using-ws-trust-from-ios-objective-c-iphone-ipad-android-java-node-js-or-any-platform-or-language/">here</a>. Also you can find the source code on my github: <a href="https://github.com/leandrob/wstrust-client">https://github.com/leandrob/wstrust-client</a></p>
<h2>Installation</h2>
<pre style="background-color: #241a10" class="code"><span style="color: #d02120"><b>$</b></span><span style="color: #f0f0f0"> npm install </span><span style="color: #e2d63c">wstrust-client</span><br /></pre>
<h2>How to use it</h2>
<pre style="background-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f0f0f0">trustClient = require(</span><span style="color: #e2d63c">'wstrust-client'</span><span style="color: #f0f0f0">);

trustClient.requestSecurityToken({
    scope: </span><span style="color: #e2d63c">'https://yourapp.com'</span><span style="color: #f0f0f0">,
    username: </span><span style="color: #e2d63c">'Your Username Here'</span><span style="color: #f0f0f0">,
    password: </span><span style="color: #e2d63c">'Your Password Here'</span><span style="color: #f0f0f0">,
    endpoint: </span><span style="color: #e2d63c">'https://your-ws-trust-endpoint-address-here'
</span><span style="color: #f0f0f0">}, </span><span style="color: #d02120">function </span><span style="color: #f0f0f0">(rstr) {

    </span><span style="color: #d5ffd5">// Access the token and enjoy it!
    </span><span style="color: #d02120">var </span><span style="color: #f0f0f0">rawToken = rstr.token;

    console.log(rawToken);

}, </span><span style="color: #d02120">function </span><span style="color: #f0f0f0">(error) {

    </span><span style="color: #d5ffd5">// Error Callback
    </span><span style="color: #f0f0f0">console.log(error)

});

</span></pre>
<p>Remember that if you are using ADFS, the endpoint that you need to use is: <em>/adfs/services/trust/13/UsernameMixed</em>.</p>
<p>Hope be useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2012/08/adfs-ws-trust-client-for-node-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Azure Access Control Service Management Client for Node.js</title>
		<link>http://leandrob.com/2012/08/windows-azure-access-control-service-management-client-for-node-js/</link>
		<comments>http://leandrob.com/2012/08/windows-azure-access-control-service-management-client-for-node-js/#comments</comments>
		<pubDate>Thu, 23 Aug 2012 02:22:00 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[Access Control Service]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Node.js Modules]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Azure Active Directory]]></category>

		<guid isPermaLink="false">http://leandrob.com/2012/08/windows-azure-access-control-service-management-client-for-node-js/</guid>
		<description><![CDATA[During the last months I’ve been working a lot with Node.js, I really like it. I’m building something huge, but I’ll talk about that later, the reason for this post is share with you a Node.js module in which I’m working on: a Windows Azure Access Control Service (recently renamed to Windows Azure Active Directory) [...]]]></description>
				<content:encoded><![CDATA[<p>During the last months I’ve been working a lot with Node.js, I really like it. I’m building something huge, but I’ll talk about that later, the reason for this post is share with you a Node.js module in which I’m working on: a Windows Azure Access Control Service (recently renamed to Windows Azure Active Directory) management client for node.js. </p>
<p>As you probably know ACS or Windows Azure Active Directory has an OData API for manage Identity Providers, Relying Parties, Rules, etc, as a requirement in the project that I’m working on we needed to use that, so together with my teammate <a href="https://github.com/machadogj/">Gustavo Machado</a> we build this nice Node.js module that allows to do that in a very simple manner. </p>
<p>You can find it on my github: <a href="https://github.com/leandrob/node-acs-cli">https://github.com/leandrob/node-acs-cli</a></p>
<h2>Installation</h2>
<pre style="background-color: #241a10" class="code"><span style="color: #d02120"><b>$</b></span><span style="color: #f0f0f0"> npm install </span><span style="color: #e2d63c">acs-cli</span><br /></pre>
<h2>&#160;</h2>
<h2>How to use it….</h2>
<pre style="background-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f0f0f0">ManagementClient = require(</span><span style="color: #e2d63c">'acs-cli'</span><span style="color: #f0f0f0">);

</span><span style="color: #d02120">var </span><span style="color: #f0f0f0">client = </span><span style="color: #d02120">new </span><span style="color: #f0f0f0">ManagementClient(</span><span style="color: #e2d63c">'[acsNamespace]'</span><span style="color: #f0f0f0">, </span><span style="color: #e2d63c">'[acs-management-key]'</span><span style="color: #f0f0f0">);

client
        .from(</span><span style="color: #e2d63c">'RelyingParties'</span><span style="color: #f0f0f0">)
        .top(</span><span style="color: #e2d63c">2</span><span style="color: #f0f0f0">)
        .query(</span><span style="color: #d02120">function </span><span style="color: #f0f0f0">(err, res) {
            </span><span style="color: #d5ffd5">///res...
        </span><span style="color: #f0f0f0">});

</span></pre>
<p>Hope be useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2012/08/windows-azure-access-control-service-management-client-for-node-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building Elastic and Resilient Cloud Applications</title>
		<link>http://leandrob.com/2012/05/building-elastic-and-resilient-cloud-applications/</link>
		<comments>http://leandrob.com/2012/05/building-elastic-and-resilient-cloud-applications/#comments</comments>
		<pubDate>Wed, 02 May 2012 21:40:00 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[P&P]]></category>
		<category><![CDATA[Personal Experiences]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Azure Integration Pack]]></category>

		<guid isPermaLink="false">http://leandrob.com/2012/05/building-elastic-and-resilient-cloud-applications/</guid>
		<description><![CDATA[During the last months I’ve been collaborating as advisor with the Microsoft Patterns and Practices Team in a very interesting project. They worked on an integration pack for Windows Azure and Enterprise library. One of the outcomes of that work is a book called “Building Elastic and Resilient Cloud Applications”. This book provides background information [...]]]></description>
				<content:encoded><![CDATA[<p>During the last months I’ve been collaborating as advisor with the Microsoft Patterns and Practices Team in a very interesting project. They worked on an integration pack for Windows Azure and <a href="http://leandrob.com/wp-content/uploads/2012/05/534475_3170485054475_1035934230_32904838_2136027959_n.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 10px 0px 0px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="534475_3170485054475_1035934230_32904838_2136027959_n" border="0" alt="534475_3170485054475_1035934230_32904838_2136027959_n" align="right" src="http://leandrob.com/wp-content/uploads/2012/05/534475_3170485054475_1035934230_32904838_2136027959_n_thumb.jpg" width="319" height="229" /></a>Enterprise library. </p>
<p>One of the outcomes of that work is a book called “Building Elastic and Resilient Cloud Applications”. This book provides background information on autoscaling and transient fault handling which makes it useful even if you don’t want to use the Application Blocks. </p>
<p>The P&amp;P guys sent me a copy of the book as a gift and they mentioned my name on the list of advisors. I am very proud and thankful of have participated in this project.</p>
<p>You can find the details on MSDN clicking <a href="http://msdn.microsoft.com/en-us/library/hh680918(v=pandp.50).aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2012/05/building-elastic-and-resilient-cloud-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Requesting a Token from ADFS 2.0 using WS-Trust with Username and Password</title>
		<link>http://leandrob.com/2012/04/requesting-a-token-from-adfs-2-0-using-ws-trust-with-username-and-password/</link>
		<comments>http://leandrob.com/2012/04/requesting-a-token-from-adfs-2-0-using-ws-trust-with-username-and-password/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 16:22:00 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[ADFS]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[WIF]]></category>

		<guid isPermaLink="false">http://leandrob.com/2012/04/requesting-a-token-from-adfs-2-0-using-ws-trust-with-username-and-password/</guid>
		<description><![CDATA[In a previous post I showed how to request tokens to ADFS using WS-Trust based on the identity of the user that requests the token. Due to I’ve received a lot of requests on the subject, here&#8217;s the code to do the same but using username and password, I mean request tokens from ADFS 2.0 [...]]]></description>
				<content:encoded><![CDATA[<p>In a <a href="http://leandrob.com/2011/11/requesting-a-token-from-adfs-2-0-using-ws-trust/">previous post</a> I showed how to request tokens to ADFS using WS-Trust based on the identity of the user that requests the token.</p>
<p>Due to I’ve received a lot of requests on the subject, here&#8217;s the code to do the same but using username and password, I mean request tokens from ADFS 2.0 using username and password based identity.</p>
<pre class="code" style="background-color: #241A10"><span style="color: #d02120">var </span><span style="color: #f8f8f8">stsEndpoint </span><span style="color: white">= </span><span style="color: #e2d63c">&quot;https://[server]/adfs/services/trust/13/UsernameMixed&quot;</span><span style="color: #f0f0f0">;
</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">relayPartyUri </span><span style="color: white">= </span><span style="color: #e2d63c">&quot;https://localhost:8080/WebApp&quot;</span><span style="color: #f0f0f0">;

</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">factory </span><span style="color: white">= </span><span style="color: #d02120">new </span><span style="color: #fab24e">WSTrustChannelFactory</span><span style="color: #f0f0f0">(
    </span><span style="color: #d02120">new </span><span style="color: #fab24e">UserNameWSTrustBinding</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">SecurityMode</span><span style="color: white">.</span><span style="color: #f8f8f8">TransportWithMessageCredential</span><span style="color: #f0f0f0">),
    </span><span style="color: #d02120">new </span><span style="color: #fab24e">EndpointAddress</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">stsEndpoint</span><span style="color: #f0f0f0">));

</span><span style="color: #f8f8f8">factory</span><span style="color: white">.</span><span style="color: #f8f8f8">TrustVersion </span><span style="color: white">= </span><span style="color: #fab24e">TrustVersion</span><span style="color: white">.</span><span style="color: #f8f8f8">WSTrust13</span><span style="color: #f0f0f0">;

</span><span style="color: #ddffdd">// Username and Password here...
</span><span style="color: #f8f8f8">factory</span><span style="color: white">.</span><span style="color: #f8f8f8">Credentials</span><span style="color: white">.</span><span style="color: #f8f8f8">UserName</span><span style="color: white">.</span><span style="color: #f8f8f8">UserName </span><span style="color: white">= </span><span style="color: #f8f8f8">user</span><span style="color: #f0f0f0">;
</span><span style="color: #f8f8f8">factory</span><span style="color: white">.</span><span style="color: #f8f8f8">Credentials</span><span style="color: white">.</span><span style="color: #f8f8f8">UserName</span><span style="color: white">.</span><span style="color: #f8f8f8">Password </span><span style="color: white">= </span><span style="color: #f8f8f8">password</span><span style="color: #f0f0f0">;

</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">rst </span><span style="color: white">= </span><span style="color: #d02120">new </span><span style="color: #fab24e">RequestSecurityToken 
</span><span style="color: #f0f0f0">{
    </span><span style="color: #f8f8f8">RequestType </span><span style="color: white">= </span><span style="color: #fab24e">RequestTypes</span><span style="color: white">.</span><span style="color: #f8f8f8">Issue</span><span style="color: #f0f0f0">,
    </span><span style="color: #f8f8f8">AppliesTo </span><span style="color: white">= </span><span style="color: #d02120">new </span><span style="color: #fab24e">EndpointAddress</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">relayPartyUri</span><span style="color: #f0f0f0">),
    </span><span style="color: #f8f8f8">KeyType </span><span style="color: white">= </span><span style="color: #fab24e">KeyTypes</span><span style="color: white">.</span><span style="color: #f8f8f8">Bearer</span><span style="color: #f0f0f0">,
};

</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">channel </span><span style="color: white">= </span><span style="color: #f8f8f8">factory</span><span style="color: white">.</span><span style="color: #f8f8f8">CreateChannel</span><span style="color: #f0f0f0">();

</span><span style="color: #fab24e">SecurityToken </span><span style="color: #f8f8f8">token </span><span style="color: white">= </span><span style="color: #f8f8f8">channel</span><span style="color: white">.</span><span style="color: #f8f8f8">Issue</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">rst</span><span style="color: #f0f0f0">);</span></pre>
<p>I hope you find it useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2012/04/requesting-a-token-from-adfs-2-0-using-ws-trust-with-username-and-password/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Request a token from ADFS using WS-Trust from iOS, Objective-C, IPhone, IPad, Android, Java, Node.js or any platform or language</title>
		<link>http://leandrob.com/2012/02/request-a-token-from-adfs-using-ws-trust-from-ios-objective-c-iphone-ipad-android-java-node-js-or-any-platform-or-language/</link>
		<comments>http://leandrob.com/2012/02/request-a-token-from-adfs-using-ws-trust-from-ios-objective-c-iphone-ipad-android-java-node-js-or-any-platform-or-language/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 05:56:00 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[ADFS]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[WIF]]></category>

		<guid isPermaLink="false">http://leandrob.com/?p=305</guid>
		<description><![CDATA[This is not just a SEO friendly name, in this post I want to show you a very easy way of providing Active Directory authentication in your apps, no matter the platform or language that you use, the only requirement is to be able to make an http post. Request for a Security Token To [...]]]></description>
				<content:encoded><![CDATA[<p>This is not just a SEO friendly name, in this post I want to show you a very easy way of providing Active Directory authentication in your apps, no matter the platform or language that you use, the only requirement is to be able to make an http post.</p>
<h2>Request for a Security Token</h2>
<p>To talk with ADFS we must be able to speak <a href="http://docs.oasis-open.org/ws-sx/ws-trust/200512/ws-trust-1.3-os.html">WS-Trust protocol</a>, on the .NET platform this is a very easy thing to do thanks to WCF and Windows Identity Foundation frameworks, but regardless the platform make a WS-Trust call is not so hard.</p>
<p>The first thing that we need to know is that <a href="http://docs.oasis-open.org/ws-sx/ws-trust/200512/ws-trust-1.3-os.html">WS-Trust protocol</a> defines an standard way of requesting security tokens, based on an XML structure known as Request Security Token or RST, this is an example of that structure:</p>
<pre style="background-color: #241a10" class="code"><span style="color: white">&lt;</span><span style="color: #d02120">trust:RequestSecurityToken </span><span style="color: #fab24e">xmlns:trust</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://docs.oasis-open.org/ws-sx/ws-trust/200512</span><span style="color: white">&quot;&gt;
  &lt;</span><span style="color: #d02120">wsp:AppliesTo </span><span style="color: #fab24e">xmlns:wsp</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.xmlsoap.org/ws/2004/09/policy</span><span style="color: white">&quot;&gt;
    &lt;</span><span style="color: #d02120">a:EndpointReference</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">a:Address</span><span style="color: white">&gt;https://yourcompany.com&lt;/</span><span style="color: #d02120">a:Address</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">a:EndpointReference</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">wsp:AppliesTo</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">trust:KeyType</span><span style="color: white">&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer&lt;/</span><span style="color: #d02120">trust:KeyType</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">trust:RequestType</span><span style="color: white">&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue&lt;/</span><span style="color: #d02120">trust:RequestType</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">trust:TokenType</span><span style="color: white">&gt;urn:oasis:names:tc:SAML:2.0:assertion&lt;/</span><span style="color: #d02120">trust:TokenType</span><span style="color: white">&gt;
&lt;/</span><span style="color: #d02120">trust:RequestSecurityToken</span><span style="color: white">&gt;</span></pre>
<p>Focusing on the basics, there is a couple of fields that are important to us, inside of the RequestSecurityToken element you will find the AppliesTo tag where, using the WS-Addressing standard, we define the scope to which the token is valid, in this case: <a href="https://yourcompany.com">https://yourcompany.com</a>.</p>
<p>RequestType specifies the action that you want to execute, in our case “Issue”, this means that we want that the (Security Token Service) STS issue a new token, but another option could be renewed an already issued token, in that case the RequestType would be “Renew”.</p>
<p>Finally, the TokenType specifies the type of the token that you want, in our case we are asking for a token based on the SAML 2.0 format.</p>
<p>Doesn’t looks very hard, isn’t? but where do we say who we are? well, one detail that adds a bit of complexity is the fact that all the WS-* protocols stack is build on top of SOAP, so we need to speak SOAP in order to send the token request. Once more, speak SOAP is not so hard, SOAP is also XML-Based, I’m not going to explain the whole SOAP protocol, but you can find the format for a soap message here: <a title="http://www.w3.org/2003/05/soap-envelope/" href="http://www.w3.org/2003/05/soap-envelope/">http://www.w3.org/2003/05/soap-envelope/</a></p>
<p>In our case, to talk with ADFS from a native client we going to use username and password security, so this is how the SOAP message will looks like: (I’ve cut some arguments to improve the presentation)</p>
<pre style="background-color: #241a10" class="code"><span style="color: white">&lt;</span><span style="color: #d02120">s:Envelope </span><span style="color: #fab24e">xmlns:s</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2003/05/soap-envelope</span><span style="color: white">&quot;
            </span><span style="color: #fab24e">xmlns:a</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2005/08/addressing</span><span style="color: white">&quot;
            </span><span style="color: #fab24e">xmlns:u</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">...</span><span style="color: white">&quot;&gt;
  &lt;</span><span style="color: #d02120">s:Header</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">a:Action </span><span style="color: #fab24e">s:mustUnderstand</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">1</span><span style="color: white">&quot;&gt;

http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue

    &lt;/</span><span style="color: #d02120">a:Action</span><span style="color: white">&gt;
</span><span style="color: white">    &lt;</span><span style="color: #d02120">a:To </span><span style="color: #fab24e">s:mustUnderstand</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">1</span><span style="color: white">&quot;&gt;https://yourcompany.com/adfs/services/trust/13/UsernameMixed&lt;/</span><span style="color: #d02120">a:To</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">o:Security </span><span style="color: #fab24e">s:mustUnderstand</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">1</span><span style="color: white">&quot; </span><span style="color: #fab24e">mlns:o</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">...</span><span style="color: white">&quot;&gt;
</span><span style="color: white">      &lt;</span><span style="color: #d02120">o:UsernameToken </span><span style="color: #fab24e">u:Id</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">uuid-6a13a244-dac6-42c1-84c5-cbb345b0c4c4-1</span><span style="color: white">&quot;&gt;
        &lt;</span><span style="color: #d02120">o:Username</span><span style="color: white">&gt;Leandro Boffi&lt;/</span><span style="color: #d02120">o:Username</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">o:Password </span><span style="color: #fab24e">Type</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">...</span><span style="color: white">&quot;&gt;P@ssw0rd!&lt;/</span><span style="color: #d02120">o:Password</span><span style="color: white">&gt;
      &lt;/</span><span style="color: #d02120">o:UsernameToken</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">o:Security</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">s:Header</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">s:Body</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:RequestSecurityToken </span><span style="color: #fab24e">xmlns:trust</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://docs.oasis-open.org/ws-sx/ws-trust/200512</span><span style="color: white">&quot;&gt;
      &lt;</span><span style="color: #d02120">wsp:AppliesTo </span><span style="color: #fab24e">xmlns:wsp</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.xmlsoap.org/ws/2004/09/policy</span><span style="color: white">&quot;&gt;
        &lt;</span><span style="color: #d02120">a:EndpointReference</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">a:Address</span><span style="color: white">&gt;https://yourcompany.com&lt;/</span><span style="color: #d02120">a:Address</span><span style="color: white">&gt;
        &lt;/</span><span style="color: #d02120">a:EndpointReference</span><span style="color: white">&gt;
      &lt;/</span><span style="color: #d02120">wsp:AppliesTo</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">trust:KeyType</span><span style="color: white">&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer&lt;/</span><span style="color: #d02120">trust:KeyType</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">trust:RequestType</span><span style="color: white">&gt;

http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue

      &lt;/</span><span style="color: #d02120">trust:Requesthttps://yourcompany.com/adfs/services/trust/13/UsernameMixedType</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">trust:TokenType</span><span style="color: white">&gt;urn:oasis:names:tc:SAML:2.0:assertion&lt;/</span><span style="color: #d02120">trust:TokenType</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">trust:RequestSecurityToken</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">s:Body</span><span style="color: white">&gt;
&lt;/</span><span style="color: #d02120">s:Envelope</span><span style="color: white">&gt;</span></pre>
<p>To quickly understand the format, the SOAP envelop has two main tags: header and body. The body of our message contains the RST (Request for Security Token) message that we created before. In the header we can find context parameters like, the Uri of the service endpoint (To), the name of the action exposed in that endpoint that you want to execute (Action), remember that in SOAP you can have multiple actions in a single endpoint, and who we are (Security), in this case username and password.</p>
<p>To use UserName and Password authentication we need to look for the action Issue in the endpoint <a href="https://yourcompany.com/adfs/services/trust/13/UsernameMixed"><em>https://yourcompany.com/adfs/services/trust/13/UsernameMixed</em></a><em>, </em>so make sure that this endpoint is enabled on ADFS configuration.</p>
<p>Once we have the SOAP message, we just need to send it to the server using a regular HTTP POST, this is an example of how to do it on .NET, but it can be applied to any platform or language:</p>
<pre style="background-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f8f8f8">client </span><span style="color: white">= </span><span style="color: #d02120">new </span><span style="color: #fab24e">WebClient</span><span style="color: #f0f0f0">();

</span><span style="color: #f8f8f8">client</span><span style="color: white">.</span><span style="color: #f8f8f8">Headers</span><span style="color: white">.</span><span style="color: #f8f8f8">Add</span><span style="color: #f0f0f0">(</span><span style="color: #e2d63c">&quot;Content-Type&quot;</span><span style="color: #f0f0f0">, </span><span style="color: #e2d63c">&quot;application/soap+xml; charset=utf-8&quot;</span><span style="color: #f0f0f0">);

</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">result </span><span style="color: white">= </span><span style="color: #f8f8f8">client</span><span style="color: white">.</span><span style="color: #f8f8f8">UploadString</span><span style="color: #f0f0f0">(
        </span><span style="color: #f8f8f8">address</span><span style="color: #f0f0f0">: </span><span style="color: #e2d63c">&quot;https://yourcompany.com/adfs/services/trust/13/UsernameMixed&quot;</span><span style="color: #f0f0f0">,
        </span><span style="color: #f8f8f8">method</span><span style="color: #f0f0f0">: </span><span style="color: #e2d63c">&quot;POST&quot;</span><span style="color: #f0f0f0">,
        </span><span style="color: #f8f8f8">data</span><span style="color: #f0f0f0">: </span><span style="color: #f8f8f8">soapMessage</span><span style="color: #f0f0f0">);</span></pre>
<p>Make sure that you specify the Content-Type header to “application/soap+xml; charset=utf-8”, what you finally need to send to the server is this:</p>
<blockquote>
<p><font size="2">POST /adfs/services/trust/13/UsernameMixed HTTP/1.1<br />
      <br />Connection: Keep-Alive </p>
<p>Content-Length: 1862 </p>
<p>Content-Type: application/soap+xml; charset=utf-8 </p>
<p>Accept-Encoding: gzip, deflate </p>
<p>Expect: 100-continue </p>
<p>Host: localhost</font></p>
<p align="left"><font size="2">&lt;s:Envelope xmlns:s=&quot;</font><a href="http://www.w3.org/2003/05/soap-envelope&quot;"><font size="2">http://www.w3.org/2003/05/soap-envelope&quot;</font></a><font size="2"> xmlns:a=&quot;</font><a href="http://www.w3.org/2005/08/addressing&quot;"><font size="2">http://www.w3.org/2005/08/addressing&quot;</font></a><font size="2"> xmlns:u=&quot;</font><a href="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;"><font size="2">http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;</font></a><font size="2">&gt;….&lt;/s:Envelope&gt;</font></p>
</blockquote>
<p align="left">I’ve added other headers to be consistent with the HTTP Protocol, but for ADFS just the Content-Type is required.</p>
<h2>The Answer: Request Security Token Response</h2>
<p>If your credentials were valid, and the scope Uri is the right one, you will get a SOAP response from ADFS. In the body of that message you will get something like this:</p>
<pre style="background-color: #241a10" class="code"><span style="color: white">&lt;</span><span style="color: #d02120">trust:RequestSecurityTokenResponseCollection </span><span style="color: #fab24e">xmlns:trust</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">...</span><span style="color: white">&quot;&gt;
  &lt;</span><span style="color: #d02120">trust:RequestSecurityTokenResponse</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:Lifetime</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">trust:Lifetime</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">wsp:AppliesTo </span><span style="color: #fab24e">xmlns:wsp</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.xmlsoap.org/ws/2004/09/policy</span><span style="color: white">&quot;&gt;...&lt;/</span><span style="color: #d02120">wsp:AppliesTo</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:RequestedSecurityToken</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">Assertion </span><span style="color: #fab24e">ID</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">_fcf06a39-c495-4074-8f22-4a7df6e26513</span><span style="color: white">&quot;
                 </span><span style="color: #fab24e">IssueInstant</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:27:24.771Z</span><span style="color: white">&quot;
                 </span><span style="color: #fab24e">Version</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2.0</span><span style="color: white">&quot; </span><span style="color: #fab24e">xmlns</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">urn:oasis:names:tc:SAML:2.0:assertion</span><span style="color: white">&quot;&gt;
        &lt;</span><span style="color: #d02120">Issuer</span><span style="color: white">&gt;http://yourcompany.com/adfs/services/trust&lt;/</span><span style="color: #d02120">Issuer</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">ds:Signature </span><span style="color: #fab24e">xmlns:ds</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2000/09/xmldsig#</span><span style="color: white">&quot;&gt;
          &lt;</span><span style="color: #d02120">ds:SignedInfo</span><span style="color: white">&gt;
            &lt;</span><span style="color: #d02120">ds:CanonicalizationMethod
              </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/10/xml-exc-c14n#</span><span style="color: white">&quot;/&gt;
            &lt;</span><span style="color: #d02120">ds:SignatureMethod
              </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/04/xmldsig-more#rsa-sha256</span><span style="color: white">&quot;/&gt;
            &lt;</span><span style="color: #d02120">ds:Reference </span><span style="color: #fab24e">URI</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">#_fcf06a39-c495-4074-8f22-4a7df6e26513</span><span style="color: white">&quot;&gt;
              &lt;</span><span style="color: #d02120">ds:Transforms</span><span style="color: white">&gt;
                &lt;</span><span style="color: #d02120">ds:Transform </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2000/09/xmldsig#enveloped-signature</span><span style="color: white">&quot;/&gt;
                &lt;</span><span style="color: #d02120">ds:Transform </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/10/xml-exc-c14n#</span><span style="color: white">&quot;/&gt;
              &lt;/</span><span style="color: #d02120">ds:Transforms</span><span style="color: white">&gt;
              &lt;</span><span style="color: #d02120">ds:DigestMethod </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/04/xmlenc#sha256</span><span style="color: white">&quot;/&gt;
              &lt;</span><span style="color: #d02120">ds:DigestValue</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">ds:DigestValue</span><span style="color: white">&gt;
            &lt;/</span><span style="color: #d02120">ds:Reference</span><span style="color: white">&gt;
          &lt;/</span><span style="color: #d02120">ds:SignedInfo</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">ds:SignatureValue</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">ds:SignatureValue</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">KeyInfo </span><span style="color: #fab24e">xmlns</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2000/09/xmldsig#</span><span style="color: white">&quot;&gt;
            &lt;</span><span style="color: #d02120">ds:X509Data</span><span style="color: white">&gt;
              &lt;</span><span style="color: #d02120">ds:X509Certificate</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">ds:X509Certificate</span><span style="color: white">&gt;
            &lt;/</span><span style="color: #d02120">ds:X509Data</span><span style="color: white">&gt;
          &lt;/</span><span style="color: #d02120">KeyInfo</span><span style="color: white">&gt;
        &lt;/</span><span style="color: #d02120">ds:Signature</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">Subject</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">SubjectConfirmation </span><span style="color: #fab24e">Method</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">urn:oasis:names:tc:SAML:2.0:cm:bearer</span><span style="color: white">&quot;&gt;
            &lt;</span><span style="color: #d02120">SubjectConfirmationData </span><span style="color: #fab24e">NotOnOrAfter</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:32:24.771Z</span><span style="color: white">&quot;/&gt;
          &lt;/</span><span style="color: #d02120">SubjectConfirmation</span><span style="color: white">&gt;
        &lt;/</span><span style="color: #d02120">Subject</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">Conditions </span><span style="color: #fab24e">NotBefore</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:27:24.756Z</span><span style="color: white">&quot; </span><span style="color: #fab24e">NotOnOrAfter</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T05:27:24.756Z</span><span style="color: white">&quot;&gt;
          &lt;</span><span style="color: #d02120">AudienceRestriction</span><span style="color: white">&gt;
            &lt;</span><span style="color: #d02120">Audience</span><span style="color: white">&gt;https://yourcompany.com/&lt;/</span><span style="color: #d02120">Audience</span><span style="color: white">&gt;
          &lt;/</span><span style="color: #d02120">AudienceRestriction</span><span style="color: white">&gt;
        &lt;/</span><span style="color: #d02120">Conditions</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">AttributeStatement</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">Attribute </span><span style="color: #fab24e">Name</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name</span><span style="color: white">&quot;&gt;
            &lt;</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;Leandro Boffi&lt;/</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;
          &lt;/</span><span style="color: #d02120">Attribute</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">Attribute </span><span style="color: #fab24e">Name</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.microsoft.com/ws/2008/06/identity/claims/role</span><span style="color: white">&quot;&gt;
            &lt;</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;Administrator&lt;/</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;
            &lt;</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;Mobile User&lt;/</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;
          &lt;/</span><span style="color: #d02120">Attribute</span><span style="color: white">&gt;
        &lt;/</span><span style="color: #d02120">AttributeStatement</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">AuthnStatement </span><span style="color: #fab24e">AuthnInstant</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:27:24.724Z</span><span style="color: white">&quot;&gt;
          &lt;</span><span style="color: #d02120">AuthnContext</span><span style="color: white">&gt;
            &lt;</span><span style="color: #d02120">AuthnContextClassRef</span><span style="color: white">&gt;
              urn:oasis:names:tc:SAML:2.0:ac:classes:Password
            &lt;/</span><span style="color: #d02120">AuthnContextClassRef</span><span style="color: white">&gt;
          &lt;/</span><span style="color: #d02120">AuthnContext</span><span style="color: white">&gt;
        &lt;/</span><span style="color: #d02120">AuthnStatement</span><span style="color: white">&gt;
      &lt;/</span><span style="color: #d02120">Assertion</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">trust:RequestedSecurityToken</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:RequestedAttachedReference</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">trust:RequestedAttachedReference</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:RequestedUnattachedReference</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">trust:RequestedUnattachedReference</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:TokenType</span><span style="color: white">&gt;urn:oasis:names:tc:SAML:2.0:assertion&lt;/</span><span style="color: #d02120">trust:TokenType</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:RequestType</span><span style="color: white">&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue&lt;/</span><span style="color: #d02120">trust:RequestType</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">trust:KeyType</span><span style="color: white">&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer&lt;/</span><span style="color: #d02120">trust:KeyType</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">trust:RequestSecurityTokenResponse</span><span style="color: white">&gt;
&lt;/</span><span style="color: #d02120">trust:RequestSecurityTokenResponseCollection</span><span style="color: white">&gt;</span></pre>
<p>This format is also specified in the WS-Trust protocol as “Request Security Token Response” or RSTR, but for you the most important section of the response is in:</p>
<blockquote>
<p>RequestSecurityToeknResponseCollection/RequestSecurityToeknResponse/RequestedSecurityToken</p>
</blockquote>
<p>The content of that tag is the security token, in our case a SAML 2.0 token:</p>
<pre style="background-color: #241a10" class="code"><span style="color: white">&lt;</span><span style="color: #d02120">Assertion </span><span style="color: #fab24e">ID</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">_fcf06a39-c495-4074-8f22-4a7df6e26513</span><span style="color: white">&quot; </span><span style="color: #fab24e">IssueInstant</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:27:24.771Z</span><span style="color: white">&quot;
                 </span><span style="color: #fab24e">Version</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2.0</span><span style="color: white">&quot; </span><span style="color: #fab24e">xmlns</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">urn:oasis:names:tc:SAML:2.0:assertion</span><span style="color: white">&quot;&gt;
  &lt;</span><span style="color: #d02120">Issuer</span><span style="color: white">&gt;http://yourcompany.com/adfs/services/trust&lt;/</span><span style="color: #d02120">Issuer</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">ds:Signature </span><span style="color: #fab24e">xmlns:ds</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2000/09/xmldsig#</span><span style="color: white">&quot;&gt;
    &lt;</span><span style="color: #d02120">ds:SignedInfo</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">ds:CanonicalizationMethod </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/10/xml-exc-c14n#</span><span style="color: white">&quot;/&gt;
      &lt;</span><span style="color: #d02120">ds:SignatureMethod </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/04/xmldsig-more#rsa-sha256</span><span style="color: white">&quot;/&gt;
      &lt;</span><span style="color: #d02120">ds:Reference </span><span style="color: #fab24e">URI</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">#_fcf06a39-c495-4074-8f22-4a7df6e26513</span><span style="color: white">&quot;&gt;
        &lt;</span><span style="color: #d02120">ds:Transforms</span><span style="color: white">&gt;
          &lt;</span><span style="color: #d02120">ds:Transform </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2000/09/xmldsig#enveloped-signature</span><span style="color: white">&quot;/&gt;
          &lt;</span><span style="color: #d02120">ds:Transform </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/10/xml-exc-c14n#</span><span style="color: white">&quot;/&gt;
        &lt;/</span><span style="color: #d02120">ds:Transforms</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">ds:DigestMethod </span><span style="color: #fab24e">Algorithm</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2001/04/xmlenc#sha256</span><span style="color: white">&quot;/&gt;
        &lt;</span><span style="color: #d02120">ds:DigestValue</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">ds:DigestValue</span><span style="color: white">&gt;
      &lt;/</span><span style="color: #d02120">ds:Reference</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">ds:SignedInfo</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">ds:SignatureValue</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">ds:SignatureValue</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">KeyInfo </span><span style="color: #fab24e">xmlns</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://www.w3.org/2000/09/xmldsig#</span><span style="color: white">&quot;&gt;
      &lt;</span><span style="color: #d02120">ds:X509Data</span><span style="color: white">&gt;
        &lt;</span><span style="color: #d02120">ds:X509Certificate</span><span style="color: white">&gt;...&lt;/</span><span style="color: #d02120">ds:X509Certificate</span><span style="color: white">&gt;
      &lt;/</span><span style="color: #d02120">ds:X509Data</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">KeyInfo</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">ds:Signature</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">Subject</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">SubjectConfirmation </span><span style="color: #fab24e">Method</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">urn:oasis:names:tc:SAML:2.0:cm:bearer</span><span style="color: white">&quot;&gt;
      &lt;</span><span style="color: #d02120">SubjectConfirmationData </span><span style="color: #fab24e">NotOnOrAfter</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:32:24.771Z</span><span style="color: white">&quot;/&gt;
    &lt;/</span><span style="color: #d02120">SubjectConfirmation</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">Subject</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">Conditions </span><span style="color: #fab24e">NotBefore</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:27:24.756Z</span><span style="color: white">&quot; </span><span style="color: #fab24e">NotOnOrAfter</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T05:27:24.756Z</span><span style="color: white">&quot;&gt;
    &lt;</span><span style="color: #d02120">AudienceRestriction</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">Audience</span><span style="color: white">&gt;https://yourcompany.com/&lt;/</span><span style="color: #d02120">Audience</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">AudienceRestriction</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">Conditions</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">AttributeStatement</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">Attribute </span><span style="color: #fab24e">Name</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name</span><span style="color: white">&quot;&gt;
      &lt;</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;Leandro Boffi&lt;/</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">Attribute</span><span style="color: white">&gt;
    &lt;</span><span style="color: #d02120">Attribute </span><span style="color: #fab24e">Name</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">http://schemas.microsoft.com/ws/2008/06/identity/claims/role</span><span style="color: white">&quot;&gt;
      &lt;</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;Administrator&lt;/</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;Mobile User&lt;/</span><span style="color: #d02120">AttributeValue</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">Attribute</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">AttributeStatement</span><span style="color: white">&gt;
  &lt;</span><span style="color: #d02120">AuthnStatement </span><span style="color: #fab24e">AuthnInstant</span><span style="color: white">=&quot;</span><span style="color: #e2d63c">2012-02-21T04:27:24.724Z</span><span style="color: white">&quot;&gt;
    &lt;</span><span style="color: #d02120">AuthnContext</span><span style="color: white">&gt;
      &lt;</span><span style="color: #d02120">AuthnContextClassRef</span><span style="color: white">&gt;
        urn:oasis:names:tc:SAML:2.0:ac:classes:Password
      &lt;/</span><span style="color: #d02120">AuthnContextClassRef</span><span style="color: white">&gt;
    &lt;/</span><span style="color: #d02120">AuthnContext</span><span style="color: white">&gt;
  &lt;/</span><span style="color: #d02120">AuthnStatement</span><span style="color: white">&gt;
&lt;/</span><span style="color: #d02120">Assertion</span><span style="color: white">&gt;</span></pre>
<p>Once we extract the token from the response, everything gets simpler: Inside of the <em>AttributeStatment</em> section you will have a list of <em>Attribute, </em>this are the claims, information of the user, for example in this token we have three different claims:</p>
<blockquote>
<ul>
<li><strong>Type:</strong> http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name </li>
<li><strong>Value:</strong> Leandro Boffi </li>
</ul>
<ul>
<li><strong>Type:</strong> http://schemas.microsoft.com/ws/2008/06/identity/claims/role </li>
<li><strong>Value: </strong>Administrator </li>
</ul>
<ul>
<li><strong>Type:</strong> http://schemas.microsoft.com/ws/2008/06/identity/claims/role </li>
<li><strong>Value:</strong> Mobile User </li>
</ul>
</blockquote>
<p>You can use those claims to perform authorization in your application, but also if your app needs to call webservices that rely on your ADFS, you will need to send the entire token in each request that you made to those services (I’ll explain this scenario in a future post).</p>
<h2></h2>
<h2>Security Features</h2>
<p>The token has some security features with which we can get us to make our application more secure. I’m not going to explain all the features in this post, but for example, if we want we can verify that no body has modified the token, because it is signed by the issuer (in our case, ADFS). You can find the signature on <em>Assertion/Signature/SignatureValue. </em>This signature is also based on a standard called XML Signature, you can find the specification here: <a href="http://www.w3.org/Signature/">http://www.w3.org/Signature/</a>.</p>
<p>Also another very important feature is the fact that the token has a limited life time, to avoid that somebody use an old token, you can find that in the <em>Assertion/Conditions/NotBefore </em>and <em>NotOnOrAfter.</em></p>
<h2>Conclusion</h2>
<p>Integrate the identity of our apps to Active Directory, no matter the platform or the language is possible due to ADFS is based on WS-Trust an standard protocol. If your language do not support WS-Trust natively it requires a bit more of effort, but as we saw in this post it’s not hard at all, you just need an XML template for the SOAP+RST call and an HTTP Post.</p>
<p>Download <a href="http://agileculture-labs.googlecode.com/files/SOAP%2BRST-Template.xml">here</a> the template for doing the SOAP-RST call, just replace the values in brackets with your values and start requesting tokens!</p>
<p>Hope has been useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2012/02/request-a-token-from-adfs-using-ws-trust-from-ios-objective-c-iphone-ipad-android-java-node-js-or-any-platform-or-language/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Claims Identity + C# 4.0 Dynamics</title>
		<link>http://leandrob.com/2012/02/claims-identity-c-4-0-dynamics/</link>
		<comments>http://leandrob.com/2012/02/claims-identity-c-4-0-dynamics/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 21:30:47 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[C# 4.0 Dynamics]]></category>
		<category><![CDATA[Claims]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[WIF]]></category>

		<guid isPermaLink="false">http://leandrob.com/2012/02/claims-identity-c-4-0-dynamics/</guid>
		<description><![CDATA[In this post I want to share with you something that I always use when I work with claim-based identity using Windows Identity Foundation. As you probably know, when you use claim-based identity in a project using WIF you have access to the user claims in the System.Thread.CurrentPrincipal.Identity property, but there is an small problem, [...]]]></description>
				<content:encoded><![CDATA[<p>In this post I want to share with you something that I always use when I work with claim-based identity using Windows Identity Foundation.</p>
<p>As you probably know, when you use claim-based identity in a project using WIF you have access to the user claims in the <em>System.Thread.CurrentPrincipal.Identity</em> property, but there is an small problem, it’s type is <em>System.Security.IIdentity</em> and to access to the claims you need to cast that property to <em>Microsoft.IdentityModel.Claims.IClaimsIdentity </em>so you end up with something like this in the middle of your app:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #f0f0f0">((</span><span style="color: #fab24e">IClaimsIdentity</span><span style="color: #f0f0f0">)</span><span style="color: #fab24e">Thread</span><span style="color: white">.</span><span style="color: #f8f8f8">CurrentPrincipal</span><span style="color: white">.</span><span style="color: #f8f8f8">Identity</span><span style="color: #f0f0f0">)</span><span style="color: white">.</span><span style="color: #f8f8f8">Claims</span></pre>
<p>That’s not sexy at all, and it gets worse if you need an specific claim, for example the email address of the user:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f8f8f8">user </span><span style="color: white">= </span><span style="color: #f0f0f0">((</span><span style="color: #fab24e">IClaimsIdentity</span><span style="color: #f0f0f0">)</span><span style="color: #fab24e">Thread</span><span style="color: white">.</span><span style="color: #f8f8f8">CurrentPrincipal</span><span style="color: white">.</span><span style="color: #f8f8f8">Identity</span><span style="color: #f0f0f0">);
            
</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">email </span><span style="color: white">= </span><span style="color: #f8f8f8">user</span><span style="color: white">.</span><span style="color: #f8f8f8">Claims</span><span style="color: white">.</span><span style="color: #f8f8f8">FirstOrDefault</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">x </span><span style="color: white">=&gt; 
    </span><span style="color: #f8f8f8">x</span><span style="color: white">.</span><span style="color: #f8f8f8">ClaimType</span><span style="color: white">.</span><span style="color: #f8f8f8">Equals</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">ClaimTypes</span><span style="color: white">.</span><span style="color: #f8f8f8">Email</span><span style="color: #f0f0f0">, </span><span style="color: #fab24e">StringComparison</span><span style="color: white">.</span><span style="color: #f8f8f8">OrdinalIgnoreCase</span><span style="color: #f0f0f0">))
    </span><span style="color: white">.</span><span style="color: #f8f8f8">Value</span><span style="color: #f0f0f0">;</span></pre>
<p>You can solve this with a simple extension method something like GetClaimValue(string claimType), and you’ll get something like this, but is still not sexy:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f8f8f8">user </span><span style="color: white">= </span><span style="color: #f0f0f0">((</span><span style="color: #fab24e">IClaimsIdentity</span><span style="color: #f0f0f0">)</span><span style="color: #fab24e">Thread</span><span style="color: white">.</span><span style="color: #f8f8f8">CurrentPrincipal</span><span style="color: white">.</span><span style="color: #f8f8f8">Identity</span><span style="color: #f0f0f0">); 
                
</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">email </span><span style="color: white">= </span><span style="color: #f8f8f8">user</span><span style="color: white">.</span><span style="color: #f8f8f8">GetClaimValue</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">ClaimTypes</span><span style="color: white">.</span><span style="color: #f8f8f8">Email</span><span style="color: #f0f0f0">);</span></pre>
<p>Wouldn’t it be better to have something like this?</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f8f8f8">email </span><span style="color: white">= </span><span style="color: #f8f8f8">user</span><span style="color: white">.</span><span style="color: #f8f8f8">Email</span><span style="color: #f0f0f0">;</span></pre>
<p>Yes, you guessed, using C# 4.0 dynamics and a little of reflection, that’s possible, we simply need to create a class called <em>DynamicIdentity</em> that extends the <em>DynamicObject </em>class, and find in the ClaimTypes (or in any class we want) the value for the type requested using the property name to search. For example, if we write <em>user.Email </em>we are asking for all the&#160; claims defined&#160; with the claim type ClaimTypes.Email (“http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress”).</p>
<p>This is how the DynamicIndentity class looks like:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">public class </span><span style="color: #fab24e">DynamicIdentity </span><span style="color: #f0f0f0">: </span><span style="color: #fab24e">DynamicObject
</span><span style="color: #f0f0f0">{
    </span><span style="color: #d02120">private </span><span style="color: #fab24e">ClaimTypeResolver </span><span style="color: #f8f8f8">claimTypeResolver</span><span style="color: #f0f0f0">;
    </span><span style="color: #d02120">private </span><span style="color: #fab24e">IEnumerable</span><span style="color: white">&lt;</span><span style="color: #fab24e">Claim</span><span style="color: white">&gt; </span><span style="color: #f8f8f8">claims</span><span style="color: #f0f0f0">;

    </span><span style="color: #d02120">public </span><span style="color: #f8f8f8">DynamicIdentity</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">IEnumerable</span><span style="color: white">&lt;</span><span style="color: #fab24e">Claim</span><span style="color: white">&gt; </span><span style="color: #f8f8f8">claims</span><span style="color: #f0f0f0">, </span><span style="color: #fab24e">ClaimTypeResolver </span><span style="color: #f8f8f8">typeResolver</span><span style="color: #f0f0f0">)
    {
        </span><span style="color: #d02120">this</span><span style="color: white">.</span><span style="color: #f8f8f8">claims </span><span style="color: white">= </span><span style="color: #f8f8f8">claims</span><span style="color: #f0f0f0">;
        </span><span style="color: #d02120">this</span><span style="color: white">.</span><span style="color: #f8f8f8">claimTypeResolver </span><span style="color: white">= </span><span style="color: #f8f8f8">typeResolver</span><span style="color: #f0f0f0">;
    }

    </span><span style="color: #d02120">public override bool </span><span style="color: #f8f8f8">TryGetMember</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">GetMemberBinder </span><span style="color: #f8f8f8">binder</span><span style="color: #f0f0f0">, </span><span style="color: #d02120">out object </span><span style="color: #f8f8f8">result</span><span style="color: #f0f0f0">)
    {
        </span><span style="color: #d02120">var </span><span style="color: #f8f8f8">claimType </span><span style="color: white">= </span><span style="color: #d02120">this</span><span style="color: white">.</span><span style="color: #f8f8f8">claimTypeResolver</span><span style="color: white">.</span><span style="color: #f8f8f8">Resolve</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">binder</span><span style="color: white">.</span><span style="color: #f8f8f8">Name</span><span style="color: #f0f0f0">);
        
        </span><span style="color: #d02120">var </span><span style="color: #f8f8f8">claims </span><span style="color: white">= </span><span style="color: #d02120">this</span><span style="color: white">.</span><span style="color: #f8f8f8">claims</span><span style="color: white">.</span><span style="color: #f8f8f8">Where</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">x </span><span style="color: white">=&gt; 
            </span><span style="color: #f8f8f8">x</span><span style="color: white">.</span><span style="color: #f8f8f8">ClaimType</span><span style="color: white">.</span><span style="color: #f8f8f8">Equals</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">claimType</span><span style="color: #f0f0f0">, </span><span style="color: #fab24e">StringComparison</span><span style="color: white">.</span><span style="color: #f8f8f8">OrdinalIgnoreCase</span><span style="color: #f0f0f0">));

        </span><span style="color: #d02120">if </span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">claims</span><span style="color: white">.</span><span style="color: #f8f8f8">Count</span><span style="color: #f0f0f0">() </span><span style="color: white">== </span><span style="color: #e2d63c">0</span><span style="color: #f0f0f0">)
        {
            </span><span style="color: #d02120">throw new </span><span style="color: #fab24e">ArgumentException</span><span style="color: #f0f0f0">(
                </span><span style="color: #d02120">string</span><span style="color: white">.</span><span style="color: #f8f8f8">Format</span><span style="color: #f0f0f0">(</span><span style="color: #e2d63c">&quot;Claim with type '{0}' was not found&quot;</span><span style="color: #f0f0f0">, </span><span style="color: #f8f8f8">claimType</span><span style="color: #f0f0f0">));
        }

        </span><span style="color: #d02120">if </span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">claims</span><span style="color: white">.</span><span style="color: #f8f8f8">Count</span><span style="color: #f0f0f0">() </span><span style="color: white">== </span><span style="color: #e2d63c">1</span><span style="color: #f0f0f0">)
        {
            </span><span style="color: #f8f8f8">result </span><span style="color: white">= </span><span style="color: #f8f8f8">claims</span><span style="color: white">.</span><span style="color: #f8f8f8">First</span><span style="color: #f0f0f0">()</span><span style="color: white">.</span><span style="color: #f8f8f8">Value</span><span style="color: #f0f0f0">;
            </span><span style="color: #d02120">return true</span><span style="color: #f0f0f0">;
        }

        </span><span style="color: #f8f8f8">result </span><span style="color: white">= </span><span style="color: #f8f8f8">claims</span><span style="color: white">.</span><span style="color: #f8f8f8">Select</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">x </span><span style="color: white">=&gt; </span><span style="color: #f8f8f8">x</span><span style="color: white">.</span><span style="color: #f8f8f8">Value</span><span style="color: #f0f0f0">)</span><span style="color: white">.</span><span style="color: #f8f8f8">ToArray</span><span style="color: #f0f0f0">();
        </span><span style="color: #d02120">return true</span><span style="color: #f0f0f0">;
    }
}
</span></pre>
<p>The ClaimTypeResolver class is responsible for resolving the Claim Type value based on the property name:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">public class </span><span style="color: #fab24e">ClaimTypeResolver
</span><span style="color: #f0f0f0">{
    </span><span style="color: #d02120">private </span><span style="color: #fab24e">Type</span><span style="color: #f0f0f0">[] </span><span style="color: #f8f8f8">typesDefinition</span><span style="color: #f0f0f0">;

    </span><span style="color: #d02120">public </span><span style="color: #f8f8f8">ClaimTypeResolver</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">Type</span><span style="color: #f0f0f0">[] </span><span style="color: #f8f8f8">typesDefinition</span><span style="color: #f0f0f0">)
    {
        </span><span style="color: #d02120">this</span><span style="color: white">.</span><span style="color: #f8f8f8">typesDefinition </span><span style="color: white">= </span><span style="color: #f8f8f8">typesDefinition</span><span style="color: #f0f0f0">;
    }

    </span><span style="color: #d02120">public string </span><span style="color: #f8f8f8">Resolve</span><span style="color: #f0f0f0">(</span><span style="color: #d02120">string </span><span style="color: #f8f8f8">friendlyName</span><span style="color: #f0f0f0">)
    {
        </span><span style="color: #d02120">foreach </span><span style="color: #f0f0f0">(</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">type </span><span style="color: #d02120">in this</span><span style="color: white">.</span><span style="color: #f8f8f8">typesDefinition</span><span style="color: #f0f0f0">)
        {
            </span><span style="color: #d02120">var </span><span style="color: #f8f8f8">field </span><span style="color: white">= </span><span style="color: #f8f8f8">type</span><span style="color: white">.</span><span style="color: #f8f8f8">GetField</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">friendlyName</span><span style="color: #f0f0f0">);

            </span><span style="color: #d02120">if </span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">field </span><span style="color: white">!= </span><span style="color: #d02120">null</span><span style="color: #f0f0f0">)
            {
                </span><span style="color: #d02120">return </span><span style="color: #f8f8f8">field</span><span style="color: white">.</span><span style="color: #f8f8f8">GetRawConstantValue</span><span style="color: #f0f0f0">()</span><span style="color: white">.</span><span style="color: #f8f8f8">ToString</span><span style="color: #f0f0f0">();
            }
        }

        </span><span style="color: #d02120">throw new </span><span style="color: #fab24e">ArgumentException</span><span style="color: #f0f0f0">(
            </span><span style="color: #d02120">string</span><span style="color: white">.</span><span style="color: #f8f8f8">Format</span><span style="color: #f0f0f0">(</span><span style="color: #e2d63c">&quot;Claim Type '{0}' was not found.&quot;</span><span style="color: #f0f0f0">, </span><span style="color: #f8f8f8">friendlyName</span><span style="color: #f0f0f0">));
    }
}</span></pre>
<p>Notice that it receives an array with the types that contains the constants for your claim types. </p>
<p>Once we have that, we just need to create and extension method of the IPrincipal class that returns this dynamic object:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">public static dynamic </span><span style="color: #f8f8f8">AsDynamic</span><span style="color: #f0f0f0">(</span><span style="color: #d02120">this </span><span style="color: #fab24e">IPrincipal </span><span style="color: #f8f8f8">user</span><span style="color: #f0f0f0">)
{
    </span><span style="color: #d02120">var </span><span style="color: #f8f8f8">claims </span><span style="color: white">= </span><span style="color: #f0f0f0">((</span><span style="color: #fab24e">IClaimsIdentity</span><span style="color: #f0f0f0">)</span><span style="color: #f8f8f8">user</span><span style="color: white">.</span><span style="color: #f8f8f8">Identity</span><span style="color: #f0f0f0">)</span><span style="color: white">.</span><span style="color: #f8f8f8">Claims</span><span style="color: white">.</span><span style="color: #f8f8f8">AsEnumerable</span><span style="color: #f0f0f0">();

    </span><span style="color: #d02120">var </span><span style="color: #f8f8f8">resolver </span><span style="color: white">= </span><span style="color: #d02120">new </span><span style="color: #fab24e">ClaimTypeResolver</span><span style="color: #f0f0f0">(</span><span style="color: #d02120">new </span><span style="color: #fab24e">Type</span><span style="color: #f0f0f0">[] 
    { 
        </span><span style="color: #d02120">typeof</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">ClaimTypes</span><span style="color: #f0f0f0">),
        </span><span style="color: #d02120">typeof</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">MyCompanyClaimTypes</span><span style="color: #f0f0f0">),
    });

    </span><span style="color: #d02120">return new </span><span style="color: #fab24e">DynamicIdentity</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">claims</span><span style="color: #f0f0f0">, </span><span style="color: #f8f8f8">resolver</span><span style="color: #f0f0f0">);
}</span></pre>
<p>That&#8217;s all, this is the final experience for the developer:</p>
<pre style="backgrond-color: #241a10" class="code"><span style="color: #d02120">var </span><span style="color: #f8f8f8">user </span><span style="color: white">= </span><span style="color: #fab24e">Thread</span><span style="color: white">.</span><span style="color: #f8f8f8">CurrentPrincipal</span><span style="color: white">.</span><span style="color: #f8f8f8">AsDynamic</span><span style="color: #f0f0f0">();

</span><span style="color: #fab24e">Console</span><span style="color: white">.</span><span style="color: #f8f8f8">WriteLine</span><span style="color: #f0f0f0">(</span><span style="color: #e2d63c">&quot;Email: {0}&quot;</span><span style="color: #f0f0f0">, </span><span style="color: #f8f8f8">user</span><span style="color: white">.</span><span style="color: #f8f8f8">Email</span><span style="color: #f0f0f0">);

</span><span style="color: #d02120">foreach </span><span style="color: #f0f0f0">(</span><span style="color: #d02120">var </span><span style="color: #f8f8f8">role </span><span style="color: #d02120">in </span><span style="color: #f8f8f8">user</span><span style="color: white">.</span><span style="color: #f8f8f8">Role</span><span style="color: #f0f0f0">)
{
    </span><span style="color: #fab24e">Console</span><span style="color: white">.</span><span style="color: #f8f8f8">WriteLine</span><span style="color: #f0f0f0">(</span><span style="color: #e2d63c">&quot;Role: {0}&quot;</span><span style="color: #f0f0f0">, </span><span style="color: #f8f8f8">role</span><span style="color: #f0f0f0">);
}</span></pre>
<p>Download the code <a href="http://agileculture-labs.googlecode.com/files/DynamicIdentity.zip">here!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2012/02/claims-identity-c-4-0-dynamics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enterprise Library Integration Pack for Windows Azure is out!</title>
		<link>http://leandrob.com/2011/12/enterprise-library-integration-pack-for-windows-azure-is-out/</link>
		<comments>http://leandrob.com/2011/12/enterprise-library-integration-pack-for-windows-azure-is-out/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 23:07:06 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[Enterprise Library]]></category>
		<category><![CDATA[P&P]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Azure Integration Pack]]></category>

		<guid isPermaLink="false">http://leandrob.com/2011/12/enterprise-library-integration-pack-for-windows-azure-is-out/</guid>
		<description><![CDATA[Today the P&#38;P Team has released the Enterprise Library Integration Pack for Windows Azure. I’ve been collaborating with the team as advisor and It was a very enriching experience. Among others, the release includes: Two news application blocks: Autoscaling Application Block (code name &#34;Wasabi&#34;) to help you to automatically scale both web and worker roles [...]]]></description>
				<content:encoded><![CDATA[<p><img style="margin: 0px 0px 10px 10px; display: inline; float: right" alt="ELAzure_logo_small" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-86-66-metablogapi/5543.ELAzure_5F00_logo_5F00_small_5F00_thumb.jpg" /></p>
<p>Today the P&amp;P Team has released the Enterprise Library Integration Pack for Windows Azure. I’ve been collaborating with the team as advisor and It was a very enriching experience.</p>
<p>Among others, the release includes:</p>
<p>Two news application blocks: </p>
<ul>
<li><strong>Autoscaling Application Block </strong>(code name &quot;Wasabi&quot;) to help you to automatically scale both web and worker roles in Windows Azure by dynamically provisioning/decommissioning roles or throttling. These scaling actions are based on timetables or on metrics collected from the application and/or Windows Azure Diagnostics.</li>
</ul>
<ul>
<li><b>Transient Fault Handling Application Block</b> (code name &quot;<i>Topaz</i>&quot;) to help you make your Windows Azure application more resilient to transient errors when you are using these cloud services: SQL Azure, Windows Azure Storage, Windows Azure Caching, and Windows Azure Service Bus.</li>
</ul>
<p>One new configuration source:</p>
<ul>
<li><b>Blob configuration source</b> to load configuration information from a blob in your Azure Storage account so that you can modify it without having to redeploy your application to Windows Azure.</li>
</ul>
<p>The release is published as a nuget package <a href="http://nuget.org/List/Search?packageType=Packages&amp;searchCategory=All+Categories&amp;searchTerm=tag%3Aelazure&amp;sortOrder=package-title&amp;pageSize=10">here</a>.</p>
<p>Enjoy it!!</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2011/12/enterprise-library-integration-pack-for-windows-azure-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Requesting a Token from ADFS 2.0 using WS-Trust</title>
		<link>http://leandrob.com/2011/11/requesting-a-token-from-adfs-2-0-using-ws-trust/</link>
		<comments>http://leandrob.com/2011/11/requesting-a-token-from-adfs-2-0-using-ws-trust/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 18:25:13 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[ADFS]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[WIF]]></category>

		<guid isPermaLink="false">http://leandrob.com/2011/11/requesting-a-token-from-adfs-2-0-using-ws-trust/</guid>
		<description><![CDATA[I’m writing this post because I saw a lot of articles on MSDN saying that to manually request a token from ADFS (something very useful for troubleshooting) you need to use the WSTrustClient class. The WSTrustClient class has been replaced for the WSTrustChannelFactory class, in order to continue with the WCF programming model with Channels. [...]]]></description>
				<content:encoded><![CDATA[<p>I’m writing this post because I saw a lot of articles on MSDN saying that to manually request a token from ADFS (something very useful for troubleshooting) you need to use the WSTrustClient class.</p>
<p>The WSTrustClient class has been replaced for the <a href="http://msdn.microsoft.com/en-us/library/microsoft.identitymodel.protocols.wstrust.wstrustchannelfactory.aspx">WSTrustChannelFactory</a> class, in order to continue with the WCF programming model with Channels. So, said that, this is the code you need to get a token from ADFS:</p>
<pre class="code"><span style="color: #d02120"><strong>var</strong> </span><span style="color: #f8f8f8">stsEndpoint </span><span style="color: white">= </span><span style="color: #e2d63c">&quot;https://[server]/adfs/services/trust/13/windowstransport&quot;</span><span style="color: #f0f0f0">;
</span><span style="color: #d02120"><strong>var</strong> </span><span style="color: #f8f8f8">relayPartyUri </span><span style="color: white">= </span><span style="color: #e2d63c">&quot;https://localhost:8080/WebApp&quot;</span><span style="color: #f0f0f0">;

</span><span style="color: #d02120"><strong>var</strong> </span><span style="color: #f8f8f8">factory </span><span style="color: white">= </span><span style="color: #d02120"><strong>new</strong> </span><span style="color: #fab24e">WSTrustChannelFactory</span><span style="color: #f0f0f0">(
<strong>    </strong></span><span style="color: #d02120"><strong>new</strong> </span><span style="color: #fab24e">WindowsWSTrustBinding</span><span style="color: #f0f0f0">(</span><span style="color: #fab24e">SecurityMode</span><span style="color: white">.</span><span style="color: #f8f8f8">Transport</span><span style="color: #f0f0f0">), 
    </span><span style="color: #d02120"><strong>new</strong> </span><span style="color: #fab24e">EndpointAddress</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">stsEndpoint</span><span style="color: #f0f0f0">));

</span><span style="color: #f8f8f8">factory</span><span style="color: white">.</span><span style="color: #f8f8f8">TrustVersion </span><span style="color: white">= </span><span style="color: #fab24e">TrustVersion</span><span style="color: white">.</span><span style="color: #f8f8f8">WSTrust13</span><span style="color: #f0f0f0">;

</span><span style="color: #d02120"><strong>var</strong> </span><span style="color: #f8f8f8">rst </span><span style="color: white">= </span><span style="color: #d02120"><strong>new</strong> </span><span style="color: #fab24e">RequestSecurityToken
</span><span style="color: #f0f0f0">{
    </span><span style="color: #f8f8f8">RequestType </span><span style="color: white">= </span><span style="color: #fab24e">RequestTypes</span><span style="color: white">.</span><span style="color: #f8f8f8">Issue</span><span style="color: #f0f0f0">,
    </span><span style="color: #f8f8f8">AppliesTo </span><span style="color: white">= </span><span style="color: #d02120"><strong>new</strong> </span><span style="color: #fab24e">EndpointAddress</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">relayPartyUri</span><span style="color: #f0f0f0">),
    </span><span style="color: #f8f8f8">KeyType </span><span style="color: white">= </span><span style="color: #fab24e">KeyTypes</span><span style="color: white">.</span><span style="color: #f8f8f8">Symmetric
</span><span style="color: #f0f0f0">};

</span><span style="color: #d02120"><strong>var</strong> </span><span style="color: #f8f8f8">channel </span><span style="color: white">= </span><span style="color: #f8f8f8">factory</span><span style="color: white">.</span><span style="color: #f8f8f8">CreateChannel</span><span style="color: #f0f0f0">();
            
</span><span style="color: #fab24e">SecurityToken </span><span style="color: #f8f8f8">token </span><span style="color: white">= </span><span style="color: #f8f8f8">channel</span><span style="color: white">.</span><span style="color: #f8f8f8">Issue</span><span style="color: #f0f0f0">(</span><span style="color: #f8f8f8">rst</span><span style="color: #f0f0f0">);
</span></pre>
<p>Note that in the example I’m using the Windows Transport endpoint, and that’s why I’m using SecurityMode.Transport when I create the binding.</p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2011/11/requesting-a-token-from-adfs-2-0-using-ws-trust/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Windows Azure Guidance Part 3 is Out!</title>
		<link>http://leandrob.com/2011/11/windows-azure-guidance-part-3-is-out/</link>
		<comments>http://leandrob.com/2011/11/windows-azure-guidance-part-3-is-out/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 15:12:54 +0000</pubDate>
		<dc:creator>Leandro Boffi</dc:creator>
				<category><![CDATA[Sin categoría]]></category>
		<category><![CDATA[P&P]]></category>
		<category><![CDATA[Windows Azure]]></category>

		<guid isPermaLink="false">http://leandrob.com/2011/11/windows-azure-guidance-part-3-is-out/</guid>
		<description><![CDATA[The Microsoft Patterns and Practices team has been working on the third party of the Windows Azure Guidance. I collaborate with the P&#38;P team as an expert advisor and is a very interesting experience. This part is focused on application integration, it shows how to integrate your applications running on premise with&#160; your cloud applications [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://leandrob.com/wp-content/uploads/2011/11/image001.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 10px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image001" border="0" alt="image001" align="right" src="http://leandrob.com/wp-content/uploads/2011/11/image001_thumb.jpg" width="223" height="229" /></a>The Microsoft Patterns and Practices team has been working on the third party of the Windows Azure Guidance. I collaborate with the P&amp;P team as an expert advisor and is a very interesting experience.</p>
<p>This part is focused on application integration, it shows how to integrate your applications running on premise with&#160; your cloud applications running on azure, showing features like Service Bus, AppFabric Cache, Traffic Manager, etc.</p>
<p>You can download the last drop in the Windows Azure Guideline site: <a href="http://wag.codeplex.com/">http://wag.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leandrob.com/2011/11/windows-azure-guidance-part-3-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
