FederatedAuthentication.WSFederationAuthenticationModule is null. How do I correct this?

Frage FederatedAuthentication.WSFederationAuthenticationModule is null. How do I correct this?

  • Montag, 3. Oktober 2011 14:40
     
      Enthält Code

    I'm working with the custom MVC sign in page sample, and trying to port this to my own (clean) MVC application.  The problem I'm having is the following variable is null, the the code following it requires it not to me null:

    WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule;

     

    Then calls this code:

     

     

      public HrdRequest(string issuer,
    
                string realm,
    
                Protocol protocol = Protocol.wsfederation,
    
                string replyTo = null,
    
                string context = null,
    
                string callback = null)
    
            {
    
                uriBuilder = new UriBuilder(issuer);
    
    
    
                parameters["protocol"] = protocol.ToString();
    
                parameters["realm"] = realm;
    
                parameters["version"] = Version;
    
    
    
                AddParameterIfNotNull("reply_to", replyTo);
    
                AddParameterIfNotNull("context", context);
    
                AddParameterIfNotNull("callback", callback);
    
            }
    

     

     

Alle Antworten

  • Montag, 3. Oktober 2011 14:59
     
     
    Is the module added into the web.config?
    Developer Security MVP | www.steveonsecurity.com
  • Montag, 3. Oktober 2011 17:57
     
      Enthält Code

    How does this look?

     

      <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </assemblies>
        </compilation>

     

     

    <system.web>
       <httpModules>
          <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
          <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
        </httpModules>

     

     

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
          <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler"/>
          <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
          <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
        </modules>

     


    • Bearbeitet ChrisLaMont Montag, 3. Oktober 2011 17:58
    •  
  • Montag, 3. Oktober 2011 18:03
     
     
    That looks right. Where is your code calling from?
    Developer Security MVP | www.steveonsecurity.com
  • Montag, 16. Januar 2012 08:40
     
     

    I ran into the same issue.  You may have found your answer already Chris, but for anyone else who wanders through here, here's what I found...

    You will get this particular null-ref exception if you don't add the STS service reference.  In order to do so, you need to install the WIF runtime and SDK and then run the federation utility on your sample project.

    The links to the runtime and sdk you need to install are in this readme for the MVC3CustomSignInPage : https://github.com/goeran/AzureAccessControlServiceDemo/blob/master/README.md

    Follow the steps there, especially the final one which runs the federation utility.  This step will get you your FederationMetadata.xml file and will resolve the null ref reported above.

    I made no other alterations to the sample other than what is covered in the config steps outlined in the readme.  Note that the readme is NOT included in the sample as downloaded from codeplex - you need to go to the source at the github link above, so it is understandable why folks are missing this step.