{"id":440,"date":"2009-06-29T13:39:00","date_gmt":"2009-06-29T22:39:00","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/2009\/06\/29\/i-made-you-a-token-but-i-eated-it-or-how-to-debug-authentication-issues-in-asp-net-with-securitytokenvisualizercontrol\/"},"modified":"2009-06-29T13:39:00","modified_gmt":"2009-06-29T22:39:00","slug":"i-made-you-a-token-but-i-eated-it-or-how-to-debug-authentication-issues-in-asp-net-with-securitytokenvisualizercontrol","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2009\/06\/29\/i-made-you-a-token-but-i-eated-it-or-how-to-debug-authentication-issues-in-asp-net-with-securitytokenvisualizercontrol\/","title":{"rendered":"I made you a token\u2026 but I eated it: or how to debug authentication issues in ASP.NET with SecurityTokenVisualizerControl"},"content":{"rendered":"<div class=\"wlWriterHeaderFooter\" style=\"float:right;margin:0px;padding:0px 0px 4px 8px\">digg_url = &#8220;http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/06\/29\/i-made-you-a-token-but-i-eated-it-or-how-to-debug-authentication-issues-in-asp-net-with-securitytokenvisualizercontrol.aspx&#8221;;digg_title = &#8220;I made you a token\u2026 but I eated it: or how to debug authentication issues in ASP.NET with SecurityTokenVisualizerControl&#8221;;digg_bgcolor = &#8220;#FFFFFF&#8221;;digg_skin = &#8220;normal&#8221;;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;<\/div>\n<p><font size=\"1\">(in case Internet memes are not your thing: before you flame me for poor grammar, know that the \u201cI eated it\u201d is intentional: see <\/font><a title=\"http:\/\/icanhascheezburger.com\/2007\/01\/15\/i-made-you-a-cookie\/\" href=\"http:\/\/icanhascheezburger.com\/2007\/01\/15\/i-made-you-a-cookie\/\"><font size=\"1\">http:\/\/icanhascheezburger.com\/2007\/01\/15\/i-made-you-a-cookie\/<\/font><\/a><font size=\"1\">)<\/font><\/p>\n<p>Another week, another <a href=\"http:\/\/code.msdn.microsoft.com\/TokenVisualizerCtrl\">sample ASP.NET control for identity<\/a>!<\/p>\n<p>There are moments in the development of claims-based websites in which you want to take a good look at the token that you are getting from the STS: if your pages are not behaving in the way you\u2019d expect, you never really know if that\u2019s because you are not getting the claims you were expecting or if you are not processing them in the right way. That\u2019s just one example of why you\u2019d want to inspect the identity info in the current context.<\/p>\n<p>Normally you have two strategies for inspecting the content of the current context:<\/p>\n<ol>\n<li><strong>You write some debugging\/tracing code<\/strong>. You know, the classic foreach on all the claims in the current IClaimsIdentity that you see so often in the samples. The approach works, but it is pretty repetitive (it\u2019s code that you rewrite almost verbatim across different projects) and it\u2019s usually not very exhaustive (maybe you print the claim values but it turns out that the issue was in the IntendedAudience).<\/li>\n<li><strong>You attach a debugger to the web app<\/strong>. This works very well, however it implies that the system allows you to do so and that\u2019s not always the case.<\/li>\n<\/ol>\n<p>Today\u2019s sample control provides you with a third way. Just drag the <a href=\"http:\/\/code.msdn.microsoft.com\/TokenVisualizerCtrl\">SecurityTokenVisualizerControl (STVC)<\/a> on your page, you\u2019ll obtain a fairly comprehensive view of what\u2019s going on in your identity context in nice tabular format, collapsible in a tiny icon so that it does not interfere too much with the rest of the page. The STVC contains code that you would otherwise write yourself in 1, and at the same time it almost as exhaustive as if you\u2019d explore the current context using 2: all this without leaving the browser.<\/p>\n<p>Below there\u2019s a copy of the documentation accompanying the <a href=\"http:\/\/code.msdn.microsoft.com\/TokenVisualizerCtrl\">sample package<\/a>. The control is extremely easy to use: as usual, remember that this is just sample code and you should be careful in using it. This time there are some issues that we felt we should highlight: you will find them in the summary section. That said, have fun!<\/p>\n<p>Kudos to the Southworks team (<a href=\"http:\/\/blogs.southworks.net\/aneisen\/\">Ariel<\/a>, <a href=\"http:\/\/blogs.southworks.net\/mwoloski\/\">Matias<\/a>, <a href=\"http:\/\/blogs.southworks.net\/tosborn\/\">Tim<\/a>, <a href=\"http:\/\/blogs.southworks.net\/dmarcet\/\">Diego<\/a>, Fernando) who helped us on this, whipping the entire thing in just a week!<\/p>\n<h1>Overview<\/h1>\n<p>The Security Token Visualizer control (STVC) is a simple ASP.NET server control which displays in a compact layout useful information about claims-based identity in a web site secured with the Geneva Framework.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"8de75977-9c90-4df4-b0c1-5daa603e3d38\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"390\" alt=\"8de75977-9c90-4df4-b0c1-5daa603e3d38\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/06\/8de75977-9c90-4df4-b0c1-5daa603e3d38_f88cbb6f-375f-4064-9337-07e4b57b62d0.png\" width=\"514\" border=\"0\" \/>     <br \/><i>Once expanded, the STVC displays information about the current identity context<\/i><\/p>\n<p>The STVC is intended to be a debugging aid, which helps you to inspect what identity info you are receiving from the STS without the need for attaching a debugger to your website. Furthermore, STVC spares you the repetitive task of writing code that retrieves and render claim values or other info about the incoming security token that are typically needed in the development &amp; testing phases of your application life cycle.<\/p>\n<h1>The Control in Action in the Sample Website<\/h1>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"779d5053-f24d-4a79-915e-161317fc6964\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"91\" alt=\"779d5053-f24d-4a79-915e-161317fc6964\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/06\/779d5053-f24d-4a79-915e-161317fc6964_934526bd-3b9f-40eb-8c6a-a6d7bba5d822.png\" width=\"262\" border=\"0\" \/>     <br \/><i>The STVC in Visual Studio\u2019s toolbox<\/i><\/p>\n<p>The sample package installs the STVC in your Visual Studio toolbox, under the <b>DPE Identity Samples<\/b> tab.<\/p>\n<p>&#160;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"44d23289-9242-4928-b2aa-b0ef3c00520c\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"319\" alt=\"44d23289-9242-4928-b2aa-b0ef3c00520c\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/06\/44d23289-9242-4928-b2aa-b0ef3c00520c_bdfdce2e-bc51-43c2-a097-c17d2667285d.png\" width=\"478\" border=\"0\" \/>     <br \/><i>The Default.aspx and Public.aspx pages in the sample solution<\/i><\/p>\n<p>The package includes a sample solution which is used for demonstrating how the control works, however its usage is so simple that you can try it on any web page from a web site protected with the Geneva Framework: just drag it on the page and you are good to go. At design time the control appears as a red token: at run time the control will maintain its design appearance, however it will also display a \u201c+\u201d sing on its left that, when clicked, will expand the control in order to show various tables containing the identity information being tracked. The only property exposed by the control, <b>Font<\/b>, influences which font settings will be used for displaying information when expanded.<\/p>\n<p>Figure 3 shows a couple of simple pages from the sample solution. Default.aspx can be reached only by users who successfully authenticated with a certain STS (included in the solution). Public.aspx can instead be reached by unauthenticated users. Both pages carry an instance of STVC.<\/p>\n<p>Let us start with Public.aspx: open a browser and navigate to <a href=\"https:\/\/localhost\/FabrikamAirlinesWebSite\/Public.aspx\">https:\/\/localhost\/FabrikamAirlinesWebSite\/Public.aspx<\/a>. <\/p>\n<p>&#160;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"f7434e57-2eb1-410f-8eb2-50870b5e1213\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"171\" alt=\"f7434e57-2eb1-410f-8eb2-50870b5e1213\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/06\/f7434e57-2eb1-410f-8eb2-50870b5e1213_38ab15a3-b2b8-481b-99ef-479ff9d08db0.png\" width=\"504\" border=\"0\" \/>     <br \/><i>STVC on a page displayed by an unauthenticated user<\/i><\/p>\n<p>Once expanded, the control will simply display a warning that the current user is not authenticated, or his or her identity is not based on claims. <\/p>\n<p>Let us now try with Default.aspx: navigate to <a href=\"https:\/\/localhost\/FabrikamAirlinesWebSite\">https:\/\/localhost\/FabrikamAirlinesWebSite<\/a>. You will be immediately redirected to a development STS, as shown below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"1bd8c110-210d-4633-9758-069320386c94\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"366\" alt=\"1bd8c110-210d-4633-9758-069320386c94\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/06\/1bd8c110-210d-4633-9758-069320386c94_fc9cdda9-d40f-40dd-a8e4-a9d0c82f03e3.png\" width=\"354\" border=\"0\" \/>     <br \/><i>The credential gathering page at the local development STS<\/i><\/p>\n<p>Just hit submit, you will land on Default.aspx. If you expand the control, you will now see the list of identity properties in the current context.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"6bb89a66-6a8f-4bbe-8ea5-a5a95f8a30b7\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"589\" alt=\"6bb89a66-6a8f-4bbe-8ea5-a5a95f8a30b7\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2009\/06\/6bb89a66-6a8f-4bbe-8ea5-a5a95f8a30b7_9d155d27-a2a5-4c0f-a79b-5bebf443e928.png\" width=\"504\" border=\"0\" \/>     <br \/><i>STVC fully populated &amp; expanded<\/i><\/p>\n<p>Figure 6 shows the kind of information STVC shows. Namely:<\/p>\n<ul>\n<li>Issued Identity \u2013 this section shows the content of the Claims collection in the first IClaimsIdentity in the current IClaimsPrincipal. For every claim we display:\n<ul>\n<li>Type <\/li>\n<li>Value <\/li>\n<li>Issuer <\/li>\n<li>Original issuer<\/li>\n<\/ul>\n<\/li>\n<li>Delegated Identity \u2013 shows claims in the delegate member of the IClaimsIdentity instance mentioned above <\/li>\n<li>Raw SAML \u2013 shows the XML of the SAML received <\/li>\n<li>SAML Properties \u2013 contains SAML-specific properties such as Intended Audience, ValidTo, certificates used to sign (from the token) and to encrypt (from the web site configuration), etc <\/li>\n<li>The signing certificate bits can be downloaded directly via the control <\/li>\n<\/ul>\n<p>It\u2019s as simple as that! <\/p>\n<h1>Summary<\/h1>\n<p>The Security Token Visualizer Control is a rudimentary but, we hope, useful tool that can help you to troubleshoot certain identity-related issues on your web pages by saving you the hassle to write repetitive debug &amp; tracing code.<\/p>\n<p>It is important to keep in mind that this is just a very simple sample, offered as a didactic tool: STVC does not pretend to be complete, should not be used in production and has various well-known shortcomings:<\/p>\n<ul>\n<li>Often the issues you need to solve prevent your web site from obtaining a token, or the token may be invalid and throw: in that case, STVC is not useful since the execution will halt before hitting its code <\/li>\n<li>While we made efforts for maintaining a pluggable architecture, the current release is strongly biased toward SAML: we wanted to make sure we covered the most common case, if you need to support different token types you can write your own handler and plug it in STVC <\/li>\n<li>Since STVC is very handy for situations in which you can\u2019t attach a debugger, the risk is that you will use liberally and end up forgetting it on live pages: that may have unintended consequences, as STVC would show info that would not be normally available. We made the icon bright red in the hope of making the control very visible and minimize the chances you will forget it on <\/li>\n<\/ul>\n<p>As usual, we hope that our sample will make your life easier as you take advantage of claims based identity and the Geneva Framework. If you have feedback, we will be glad to do our best for incorporating it in the next deliverables.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>digg_url = &#8220;http:\/\/blogs.msdn.com\/vbertocci\/archive\/2009\/06\/29\/i-made-you-a-token-but-i-eated-it-or-how-to-debug-authentication-issues-in-asp-net-with-securitytokenvisualizercontrol.aspx&#8221;;digg_title = &#8220;I made you a token\u2026 but I eated it: or how to debug authentication issues in ASP.NET with SecurityTokenVisualizerControl&#8221;;digg_bgcolor = &#8220;#FFFFFF&#8221;;digg_skin = &#8220;normal&#8221;;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined; (in case Internet memes are not your thing: before you flame me for poor grammar, know that the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1422,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[88,75,74,9],"tags":[],"class_list":["post-440","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-beta2","category-geneva","category-geneva-framework","category-identity"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=440"}],"version-history":[{"count":0,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/440\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media\/1422"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}