title: OWIN - Customizing UserManager
body: <p>I had to customize the <code>UserManager</code> class to find and authenticate users in the company structure (mixes Active Directory Authentication with another Oracle Authetication). Though I have implemented the <code>FindAsync</code> and <code>CreateIdentityAsync</code>, the user is not set as authenticated.</p>
  
  <p>My <code>UserManager</code> implementation:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Dynamic;
  using System.Security.Claims;
  using System.Web;
  using MyProject.Common;
  using MyProject.Models;
  using Microsoft.AspNet.Identity;
  using System.Threading.Tasks;
  
  namespace MyProject.Infrastructure
  {
      public class GNUserManager : UserManager&lt;ApplicationUser&gt;
      {
          public GNUserManager(IUserStore&lt;ApplicationUser&gt; store) : base(store)
          {
  
          }        
  
          public override async Task&lt;ApplicationUser&gt; FindAsync(string userName, string password)
          {
              /* Performs some logic here that returns true */
  
              if (foundUser) {
                  return await Task.Run(() =&gt; new ApplicationUser
                  {
                      UserName = userName, 
                      Id = userName
                  });
              }
  
              throw new Exception("User not found.");
          }
  
          public override async Task&lt;ClaimsIdentity&gt; CreateIdentityAsync(ApplicationUser user, string authenticationType)
          {
              IList&lt;Claim&gt; claimCollection = new List&lt;Claim&gt;
              {
                  new Claim(ClaimTypes.Name, user.UserName),
                  new Claim(ClaimTypes.Country, "Brazil"),
                  new Claim(ClaimTypes.Email, user.UserName)
              };
  
              var claimsIdentity = new ClaimsIdentity(claimCollection, "Company Portal");
  
              return await Task.Run(() =&gt; claimsIdentity);  
          }
      }
  }
  </code></pre>
  
  <p>What is lacking to have my user authenticated?</p>