title: How to do programmatic sign in using aspnet Identity Framework v2?
body: <p>I'm cobbling together snippets of code from blogs and different places to try to get this to work.  Normally, I'd refer to the reference documentation, but I can't find it <a href="http://www.asp.net/identity" rel="nofollow">here</a> or anywhere else.  It's just videos and demos for specific use cases that include user management or facebook or twitter.</p>
  
  <p>I have a proprietary authentication service that I'm using.  User accounts are not managed inside my application.  So I need to be able to sign in a user that's completely constructed at run time.</p>
  
  <p>Here's what I'm trying now in my MVC app.</p>
  
  <pre><code>using System.Security.Claims;
  
  public class HomeController : Controller {
      public ActionResult Scratch() {
          var claims = new Claim[] {
              new Claim(ClaimTypes.Name, "somename"),
              new Claim(ClaimTypes.NameIdentifier, "someidentifier"),
              new Claim("foo", "bar"),
          };
  
          var identity = new ClaimsIdentity(claims);
  
          var authenticationManager = HttpContext.GetOwinContext().Authentication;
          authenticationManager.SignIn(identity);
  
          return Content(
              $"authentication manager type: {authenticationManager.GetType()} \n"
              + $"authenticated: {HttpContext.User.Identity.IsAuthenticated} \n"
              + $"user name: {HttpContext.User.Identity.Name} \n",
              "text/plain");
      }
  }
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>authentication manager type: Microsoft.Owin.Security.AuthenticationManager 
  authenticated: False 
  user name:  
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Why does the output show that the user has not been authenticated?  What more do I have to do to get this user authenticated?</li>
  <li>Where is the documentation for this framework?  </li>
  </ol>
  
  <h2>Update</h2>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>public partial class Startup {
      public void Configuration(IAppBuilder app) {
          ConfigureAuth(app);
          ConfigureAnalyticContext(app);
      }
  }
  </code></pre>
  
  <p><strong>Startup.Auth.cs:</strong> </p>
  
  <p>(there is actually <em>much</em> more, but all the rest has been commented out, in search of finding a minimal configuration that works)</p>
  
  <pre><code>public partial class Startup {
      public void ConfigureAuth(IAppBuilder app) {
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
      }
  }
  </code></pre>
  
  <p><strong>AnalyticContext.Auth.cs</strong></p>
  
  <p>(this is my Entity Framework context, I doubt it's related to this problem)</p>
  
  <pre><code>public partial class Startup {
      public void ConfigureAnalyticContext(IAppBuilder app) {
          app.CreatePerOwinContext(() =&gt; CentoAnalyticsContext.Create());
      }
  }
  </code></pre>