Showing posts with label Windows Identity Foundation. Show all posts
Showing posts with label Windows Identity Foundation. Show all posts

Wednesday, August 26, 2015

Claims Transformation in ASP.NET MVC

If you are looking for a way to transform claims for Claims Augmentation, then you will definitely want to take a look at the following articles:

How To: Transform Incoming Claimshttps://msdn.microsoft.com/en-us/library/hh987036(v=vs.110).aspx

This series is a 4-part series which goes over Claims Transformation in great detail:

http://dotnetcodr.com/2013/02/25/claims-based-authentication-in-mvc4-with-net4-5-c-part-1-claims-transformation/

http://dotnetcodr.com/2013/02/28/claims-based-authentication-in-mvc4-with-net4-5-c-part-2-storing-authentication-data-in-an-authentication-session/

http://dotnetcodr.com/2013/02/18/introduction-to-claims-based-security-in-net4-5-with-c-part-3-claims-transformation/

http://dotnetcodr.com/2013/02/21/introduction-to-claims-based-security-in-net4-5-with-c-part-4-authorisation-with-claims/


Thursday, August 20, 2015

Windows Identity Foundation Cross-Browser Compatibility Issues

I was recently building an ASP.NET MVC Web Application using .NET v. 4.5 with Windows Identity Foundation and Forms Authentication based on this article: http://brockallen.com/2013/01/26/replacing-forms-authentication-with-wifs-session-authentication-module-sam-to-enable-claims-aware-identity/

Unfortunately, I discovered a very unexpected behavior!!

I tested the following browsers:

  • Internet Explorer 11
  • Google Chrome
  • Mozilla Firefox 39

When I logged in with Internet Explorer 11 and navigated back and forth between 2 WIF Sites (Development and Staging), I was never being redirected from the Forms Authentication window!




When I logged in with Google Chrome and navigated back and forth between 2 WIF Sites (Development and Staging), I was never being redirected from the Forms Authentication window!  Sometimes, I would even lose my FedAuth cookies!!




However, when I logged in with Mozilla Firefox 39 and navigated back and forth between 2 WIF Sites (Development and Staging), everything worked perfectly!!





If you are also experiencing this issue, please vote on this Connect bug here: https://connect.microsoft.com/VisualStudio/feedback/details/1693417

Tuesday, August 18, 2015

FedAuth Cookies ARE Case-Sensitive!!

I was recently working with Windows Identity Foundation and FedAuth Cookies when I noticed that my application kept on losing my FedAuth Cookie information!

Well, after doing some debugging and troubleshooting with Microsoft, I was able to find this line in my RouteConfig.cs file:

routes.LowercaseUrls = true;

Well, as it turns out, this line was causing my Urls to switch context from /MyUrl to /myurl.  Since my FedAuth Cookies were being created at the time of login, when the Url in my application changes, I suddenly lost my FedAuth Cookies!

Well, once I determined that this behavior was occurring, I decided that I needed to change that code to this instead:

routes.LowercaseUrls =false;

Now my application retained my Url all the way through the application and I no longer lost my FedAuth Cookie information!!

Wednesday, August 12, 2015

Claims-Aware ASP.NET Web Applications using Windows Identity Foundation

I was recently researching for a definitive MSDN article on how to implement a Claims-Aware ASP.NET Web Application using Windows Identity Foundation (now built into .NET v. 4.5) and I came across this article:  https://msdn.microsoft.com/en-us/library/hh291061%28v=vs.110%29.aspx

The article provides links to implementing this using ASP.NET Web Forms, ASP.NET MVC both with WIF as well as with Forms Authentication!

Unfortunately, no code samples are provided and no additional details are provided regarding how to customize the Claims information any further, so these articles definitely leave a lot to be desired, but it should at least get you started working with Claims-Aware ASP.NET Web Applications!!

If you want some more detailed information about how to customize this further, you can check out articles similar to this one: http://brockallen.com/2013/01/26/replacing-forms-authentication-with-wifs-session-authentication-module-sam-to-enable-claims-aware-identity/

Thursday, August 6, 2015

Using Claims-based Forms Authentication with ASP.NET MVC

If you are attempting to use Claims within your ASP.NET MVC Web Application, you may encounter problems if you are not using a Claims Provider such as ADFS as your Claims Issuer.

Since I was using Forms Authentication and the FormsIdentity object, I was encountering a problem whereby only a single Claim was always being returned with my FormsIdentity object.  Based on older code, I was also using a GenericPrincipal object. 

I discovered that I needed to use ClaimsIdentity and ClaimsPrincipal instead in order to add more claims to be passed around with my User Identity as described in this article: http://martinwilley.com/blog/2014/03/07/FormsAuthenticationWithClaims.aspx

Once I solved that problem, since I was sending my own set of Claims from my ASP.NET Web API Service Layer, I suddenly encountered the error message as described in this article: https://stack247.wordpress.com/2013/02/22/antiforgerytoken-a-claim-of-type-nameidentifier-or-identityprovider-was-not-present-on-provided-claimsidentity/

Since I was using AntiForgeryTokens in my ASP.NET MVC Web Application, I was encountering this exception at runtime.

Fortunately, the solution provided in the article for setting the AntiForgeryConfig.UniqueClaimTypeIdentifier in my Global.asax.cs file was just what I needed!!

Friday, January 9, 2015

Identity and Access Tool for Visual Studio 2013

If you have been working with Windows Identity Foundation in the past, you may have known about the Identity and Access Tool that was available with Visual Studio 2012 (that was previously available through the Windows Identity Foundation SDK in Visual Studio 2010).  You could download the Identity and Access Tool from Visual Studio Gallery here: https://visualstudiogallery.msdn.microsoft.com/e21bf653-dfe1-4d81-b3d3-795cb104066e

However, if you check Visual Studio Gallery, you will notice that there is no update for the Identity and Access Tool for Visual Studio 2013 even though several features/functionality are missing in the Visual Studio 2013 release that were previously available through the Identity and Access Tool extension.

According to another article, Microsoft is aware of the deficiencies in Visual Studio 2013: http://bartwullems.blogspot.com/2013/11/visual-studio-2013-where-is-identity.html

Therefore, if you are continuing to develop with Identity-based solutions that require Claims authentication, for the time being, you are forced to use Visual Studio 2012.

In addition, you can vote for this UserVoice item so that hopefully Microsoft includes this functionality in a future release of the Visual Studio IDE:

Thursday, May 29, 2014

Windows Identity Foundation with .NET 4.5

If you have ever used Windows Identity Foundation in the past, you may already know that Microsoft decided to integrate Windows Identity Foundation directly into the .NET Framework v. 4.5.

In the past, you would have to install Windows Identity Foundation separately and then also install the Windows Identity Foundation SDK in order to use the available templates in Visual Studio.

However, with Windows Identity Foundation in .NET v. 4.5, you only need to install the Identity and Access Tool from the Visual Studio Gallery: http://visualstudiogallery.msdn.microsoft.com/e21bf653-dfe1-4d81-b3d3-795cb104066e

Unfortunately, this tool only supports Visual Studio 2012 :-(   If you think Microsoft should add support for the Visual Studio 2013 IDE, you can vote for this item here: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/5987303-provide-identity-and-access-tool-support-for-visua

You can learn more about how to work with Windows Identity Foundation in .NET 4.5 here: http://msdn.microsoft.com/en-us/library/hh377151.aspx

 


Thursday, August 16, 2012

Visual Studio 2012 and .Net 3.5 on Windows 8

If you currently develop applications which run on .Net Framework v. 3.5 and you install Visual Studio 2012 on Windows 8, you should know that BY DEFAULT, Windows 8 does not have an installed version of Microsoft.Net Framework v. 3.5.

Therefore, it will not appear in Visual Studio 2012 as depicted below:


Therefore, you will have to go into the Control Panel-->Programs and Features-->Turn Windows features on or off, and install .Net Framework v. 3.5 support.


Simultaneously, if you wish, you can also install Windows Identity Foundation 3.5 support:


If everything installs as expected, you should then be able to see all of the relevant .Net Development Frameworks as shown below:



Friday, March 16, 2012

Identity and Access Tool for Visual Studio 11

Microsoft is finally making it easier to support Claims-based identity in all of the applications that developers are creating in Visual Studio 11.  They have recently published an extension for Visual Studio 11 to the Visual Studio 11 Gallery that supports various supports of Web Applications including ASP.Net MVC and WCF Services:

http://visualstudiogallery.msdn.microsoft.com/e21bf653-dfe1-4d81-b3d3-795cb104066e?SRC=Home

Too bad it only supports these features for .Net 4.5....

Saturday, March 10, 2012

Security Token Visualizer Control for Visual Studio 2010

If you are working with Windows Identity Foundation and you are using Visual Studio 2010, you won't be able to readily find any reference or mention to using the Security Token Visualizer Control for Visual Studio 2010 on any Windows Identity Foundation related websites.

Interestingly enough, Microsoft DID release a newer version of the Security Token Visualizer Control for Visual Studio 2010, but it is associated with Windows Azure! 

You can find out how to use the Security Token Visualizer Control for both Windows Identity Foundation and Windows Azure applications here:
http://msdn.microsoft.com/en-us/gg557904

The source code for the Visual Studio 2010-compatible Security Token Visualizer Control can be directly downloaded here: http://az12722.vo.msecnd.net/identitytrainingcourse1-6/labs/introtoacslabsv21-2/Source.zip

Saturday, February 25, 2012

Digest Verification Error when editing FederationMetadata.xml

If you have ever had to manually edit the FederationMetadata.xml file, you may encounter a Digest Verification Error message while attempting to use the modified file with the Federation Utility.

The root cause of this is that the FederationMetadata.xml file is signed with a Digital Signature to prevent tampering of the file.  Therefore, when you manually edit the file, the digital signature hash value will not match the original hash value contained in the file thus throwing the Digest Verification Error/Exception.

One of the solutions to resolving this problem is provided here: http://blogs.windowsclient.net/anshulee/archive/2010/09/16/federation-metadata-generator.aspx

You can basically remove the element beginning with ds:Signature and then run it through the Federation Utility wizard again.

Alternatively, you can completely re-generate the FederationMetadata.xml file as well using the Federation Metadata Generator tool.

However, a better alternative is to simply use the STS Federation Metadata Editor tool that can be downloaded from here: http://stsmetadataeditor.codeplex.com/

You can then manually remove the ds:Signature element and then Load the Metadata into the editor and save the modified FederationMetadata.xml file. 

In addition, the latest Source Code changeset (changeset #96419) for this tool will automatically remove this element for you if a Cryptographic Exception is thrown, thereby allowing you to re-load the file, make your changes and save the new file!

Thursday, January 12, 2012

Finding the WIF SDK Visual Studio Project Templates

If you are looking for the Windows Identity Foundation SDK Visual Studio Project Templates, you can find them here:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\Web\CSharp\1033
OR
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\Web\CSharp\1033

Extracting the .zip files and examining the contents can be useful in determining how to create your own WIF-based Visual Studio project templates.  If you have noticed, the WIF-based Visual Studio project templates installed by the WIF SDK also automatically run the FedUtil wizard in the background.

You will find this within the .vstemplate file:


  <WizardExtension>
    <Assembly>
      Microsoft.IdentityModel.Tools.VS, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    </Assembly>
    <FullClassName>Microsoft.IdentityModel.Tools.VS.STSTemplateWizard</FullClassName>
  </WizardExtension>


You can then utilize this content in your own WIF-based Visual Studio project templates by manually editing the resultant .vstemplate files.

Tuesday, January 10, 2012

Security Token Services

As you may already know, you can create sample STS Web Sites using the WIF (Windows Identity Foundation) SDK through the installed Visual Studio project templates.

However, if you are looking anything more complex than the basic STS templates provided to you, you can look at these 2 CodePlex projects which offer a bit more functionality than the out-of-the-box STS functionality:

  1. http://startersts.codeplex.com/
  2. http://identityserver.codeplex.com/
The Identity Server project is a bit newer project, but you can use either of the projects for development purposes.  The projects are meant as a good reference for how to implement your own custom STS.

Wednesday, August 24, 2011

SelfSTS Tool

If you have used the Windows Identity Foundation SDK, you have probably seen how easy it is to develop an STS project from within Visual Studio.

However, if you want to set up an STS rather easily and you do not have Visual Studio readily available, the SelfSTS tool makes it rather quick and simple to create an STS for your ASP.Net or SharePoint application.

You can download the SelfSTS tool from here: http://archive.msdn.microsoft.com/SelfSTS

Monday, April 4, 2011

Where can I find the Microsoft.IdentityModel DLL?

If you use any code analysis tools such as FxCop for any of your Windows Identity Foundation assemblies, you may encounter an error message such as the following:

Project : error : CA0001 : The following error was encountered while reading module 'UserClaims': Assembly reference not resolved: Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
Project : error : CA0058 : The referenced assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be found. This assembly is required for analysis and was referenced by: '.dll'.

Since it is not readily obvious as to where this assembly is located, you must look for it in the location where you have installed the Windows Identity Foundation SDK. This will usually be in one of the following locations:

1. C:\Program Files\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\Microsoft.IdentityModel.dll
2. C:\Program Files (x86)\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\Microsoft.IdentityModel.dll

Once you create the appropriate directory/assembly reference for FxCop, this should resolve the error message and you should be able to continue performing your code analysis!

Friday, February 25, 2011

Clearing cookies with IE 8's Developer Tools

If you have been working with Windows Identity Foundation, you probably already know that it is not as easy to clear out cookies using Internet Explorer as it is with alternative browsers such as Mozilla Firefox and Google Chrome.

However, if you are forced to work with Internet Explorer 8, there is still a way of managing cookies.  That method is through the use of the Developer Tools which ship with Internet Explorer 8.

  1. Browse to the website in Internet Explorer from which you want to remove/delete the associated cookies.
  2. From the Tools menu (or F12), you can open the Developer Tools. 
  3. You can then open the Cache menu
  4. Beneath the Cache menu, you will see several options for managing cookies
  5. However, unlike the Remove Individual Cookies option in Mozilla Firefox and Google Chrome, you will not find such an option.
  6. Instead, you will have to select the menu option for Clear Session Cookies
  7. After you click on that option, you must now select the menu option for Clear Cookies for Domain
  8. After that is done, you should be able to log into your website (probably your STS) using different login credentials.

Wednesday, February 23, 2011

Why Mozilla Firefox and Google Chrome are better than IE for development

If you have been developing with Windows Identity Foundation at all using Claims-aware Web Sites and a Security Token Service, you may have realized some of the frustrations with developing using Internet Explorer.

The way in which Claims-aware applications work in conjunction with an STS, is that the token information is stored in a cookie on your browser. 

Well, if you are testing tokens from multiple users to see how they render differently, as you can probably guess, this becomes a bit of a problem.  Since the cookies are stored locally on your browser, even when you close the window, the cookie is not deleted from your machine.  Therefore, the next time you attempt to log into the system, you are automatically re-directed because the cookie is still present.

Unfortunately, unlike Mozilla Firefox or Google Chrome, there is no easy way to manage these cookies and remove individual cookies.  Even using the new Developer Tools available with IE 8 does not provide this capability. 

But, if you are using Firefox or Chrome, you can simply use the option to Remove Individual Cookies.  Using this capability, you can simply delete the cookies (from localhost or elsewhere) that were placed on your machine.  Once the identification information has been removed from the browser, you can now log in as an alternative user.

Below is a screenshot from the Cookie Manager present in Firefox.  You can find this tool under Tools-->Options-->Privacy-->remove individual cookies (hyperlink)

Monday, February 21, 2011

Where is my STSTestCert?

If you have recently installed the Windows Identity Foundation SDK, you may be lucky enough to have had the STSTestCert X509 Certificate properly installed on your local machine.

If you are one of those unfortunate few who did not get the STSTestCert X509 Certificate installed on your machine, fear not, there is still hope for you.


  1. First of all, the easiest way (that I prefer) to check if you have the STSTestCert properly installed is to open the IIS 7/7.5 Management Console.  
  2. In the Features view, click on Server Certificates
  3. Review the list of Server Certificates
  4. If you cannot find STSTestCert listed amongst the installed certificates, your installation of Windows Identity Foundation SDK did not install the certificate for you.

Well, if you are in this situation, you should still be able to get the STSTestCert installed on your system.

  1. Launch Visual Studio 2010
  2. From the File menu, select New-->Web Site
  3. Look at the various project templates for C#
  4. Make sure the Target Framework is .Net Framework 4
  5. Create a new ASP.Net Security Token Service Web Site project
  6. Now repeat the steps listed above to review the Server Certificates installed in the IIS Management Console
  7. You should now be able to find the STSTestCert Server Certificates amongst the list of installed certificates

Friday, February 18, 2011

Where is the STSTestCert stored

When you install the Windows Identity Foundation SDK, a development X509 certificate is installed on your local machine.

Interestingly enough, while most certificates are installed in the Personal certificate store, the STSTestCert certificate is actually installed in the Trusted People store.

If you ever used an earlier source code build of the STS Federation Metadata Editor http://stsmetadataeditor.codeplex.com/, you would notice that the list of Installed X509 Certificates that were displayed were from the Personal certificate store and therefore would not display the STSTestCert.  Fortunately, the code has been changed and updated to load installed certificates from the Local Machine rather than just from the User store.

Quote of the Day:

Everyone should live in Michigan!  You can either go to Paradise (Michigan) or you can go to Hell (Michigan).

Thursday, February 17, 2011

Fixing the ID4175 Error Message

If you have been working extensively with Windows Identity Foundation and using Claims-aware application with a Security Token Service, chances are you have seen the following dreaded error:


ID4175: The issuer of the security token was not recognized by the IssuerNameRegistry. To accept security tokens from this issuer, configure the IssuerNameRegistry to return a valid name for this issuer.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IdentityModel.Tokens.SecurityTokenException: ID4175: The issuer of the security token was not recognized by the IssuerNameRegistry. To accept security tokens from this issuer, configure the IssuerNameRegistry to return a valid name for this issuer.



After doing quite a bit of research on this error message, I finally found a blog posting/article which indicated how to solve this error message rather easily!

  1. First, open the Web.config file of the Claims-aware Web Site
  2. Look for the element that looks like this: <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <trustedIssuers>
    <add thumbprint="E1787F034DAA4F5401811F72F9B64E138FE6FF2F" name="http://localhost:48924/WingtipSTS/" />
    </trustedIssuers>
    </issuerNameRegistry>
  3. Now simply delete/remove this element entirely from the Web.config file
  4. Save your changes to the Web.config file
  5. Right click on the Claims-aware Web Site project and select Add STS Reference
  6. Proceed through the Federation Utility wizard once more to connect to the appropriate STS
  7. After the Federation Utility wizard completes successfully, the issuerNameRegistry element should have been re-added back to the Web.config
  8. Right click on the Default.aspx web form and select View in Browser 
  9. Verify that the Claims-aware Web Site now authenticates to the STS successfully!

In some cases, if you are working with existing code samples (such as can be downloaded from MSDN Code Gallery), the above set of steps will not work for you.  This is because using Add STS Reference actually reads the FederationMetadata.xml file contained in the STS.  Often, this file has been signed with the STSTestCert with a Thumbprint which differs from the Thumbprint of the STSTestCert which is installed on your local machine.  This Thumbprint is subsequently added to the Web.config file of your Claims-aware Web Site.

Fortunately, a CodePlex project called STS Federation Metadata Editor can be used for editing these FederationMetadata.xml files. The CodePlex project is located here: http://stsmetadataeditor.codeplex.com/

Once you edit and re-save these files using the Metadata Editor, you should be able to use the above set of steps for Add STS Reference to ensure that your Claims-aware Web Site is working properly and has all of the proper Web.config values.