title: Where to create custom Identity with WIF in a MVC application?
body: <p>Prior to WIF, <code>Application_PostAcquireRequestState</code> was a good place to create a custom Identity, but required a lot of framework to make sure each type of authentication you were doing was mapped appropriately. By custom Identity, I mean a class inheriting from Identity such as the below SomeIdentity, so that we could have a specific property we might require all authenticated users to have.</p>
  
  <p>PostAcquirerequestState is still available, but there's alot of new ways you can hook into authentication with.  Additionally, old methods become complex when supporting multiple authentication methods.  </p>
  
  <p>I'd like to know if there's a better way than the below to accomplish this now in WIF.  Primarily I'd like to separate out the code that handles mapping claims to the Identity.  The idea being that code would be different for other authentication types/providers, as the way it retrieves that property value may not be from a claim such as with SAML, but from somewhere else for other types of authentication methods.  I am using <code>Kentor.AuthServices</code> for SAML support currently.  While there might be different code for mapping those values depending on the provider, the end result would be that a SomeIdentity instance had been created and it's SomeProperty and other properties would be set.  This way the rest of the application can always depend/assume those have been handled.</p>
  
  <p>My MVC project came with a <code>AccountController</code> that had a <code>ExternalLoginCallback</code> which the name implied might be a good hook for when an external authentication completed(which to me SAML is an "external" authentication).  However, it does not seem to be hit at any point during/after a SAML authentication.</p>
  
  <p>It may be the answer is that we still need to piece this together ourselves the old way, but I was hoping WIF had some better framework hooks to make this easier.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public sealed class SomeIdentity : Identity
  {
    ...
    // Some custom properties
    public string SomeProperty { get;set;}
  }
  
  protected void Application_PostAcquireRequestState(object sender, EventArgs e)
  {
    ...
    identity = new SomeIdentity(id, userId);
    // map a claim to a specific property
    identity.SomeProperty = ...Claims[IdpSomePropertyKey];
    ///...
  
    GenericPrincipal newPrincipal = new GenericPrincipal(identity , null);
    HttpContext.Current.User = newPrincipal;
    System.Threading.Thread.CurrentPrincipal = newPrincipal;
  }
  </code></pre>
  
  <p><strong>Now that I'm using WIF, where should I be putting code that is specific to a particular authentication type(i.e. Kentor.AuthServices SAML) which creates a custom SomeIdentity?</strong>  </p>
  
  <p>The idea being that SomeIdentity would be the identity class used everywhere in my application, but the code to populate it's properties will need to be written specifically for each authentication type, such as with SAML to pull claims and use their values to set the proeprties.  I.e. it is where the mapping occurs.</p>