I am trying to combine FederatedAuthentication with .NET 4.5, MVC 4 and active forwarding using a custom server login page using the code in this tutorial and this sample code.
Redirecting to the LogOn method of my AccountController works fine, and the method looks like this:
public ActionResult LogOn() { HrdClient hrdClient = new HrdClient(); WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule; HrdRequest request = new HrdRequest(fam.Issuer, fam.Realm, context: Request.QueryString["ReturnUrl"]); IEnumerable<HrdIdentityProvider> hrdIdentityProviders = hrdClient.GetHrdResponse(request); ViewData["Providers"] = hrdIdentityProviders; return View(); }
This does not work because FederatedAuthentication.WSFederationAuthenticationModule is null.
Using VS 2012, I launched a new authentication and access wizard (which seems to replace the old STS dialog). This gave me the FederationMetadata folder, which looks correct, and a few changes in my Web.Config. In particular, the module section is as follows:
<system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true"> <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" /> <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" /> </modules>
And, seeing the answers of SO 8937123 and 8926099 , I added the following as well:
<httpModules> <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </httpModules>
And finally, in my nuget package set, Microsoft.IdentityModel is displayed, which the MVC application correctly references:
<packages> <package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net45" /> </packages>
I also saw this question regarding social.msdn, which seems to suggest that you need to start the STS dialog.
Can someone explain why FederatedAuthentication.WSFederationAuthenticationModule will be null, and what can I do to prevent this from happening?