title: I can't seem to get a very basic cookie login example to work with MVC5 and OWIN
body: <p>I've been trying to get my feet wet with ASP.net MVC 5 for 2013, but so far I've failed to get even the most basic authentication working correctly.</p>
  
  <p>I've been reading around for the last few days and I finally stumbled upon (<a href="http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/" rel="nofollow">http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/</a>) which seemed to give the most basic simple example I could find. So I tried that, but it still fails to seem to actually create a session for the user.</p>
  
  <p>Here is my cookie config</p>
  
  <pre><code>public void ConfigureAuth(IAppBuilder app)
      {
          app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              LoginPath = new PathString("/FooBar")
          });
      }
  </code></pre>
  
  <p>Here is my basic custom login.</p>
  
  <pre><code>public class LoginController : ApiController
      {
          private IAuthenticationManager Authentication
          {
              get { return Request.GetOwinContext().Authentication; }
          }
  
          // POST api/login
          public void Post([FromBody]LoginInfo email)
          {
              var fooBar = Authentication.User;
              var claims = new List&lt;Claim&gt;
              {
                  new Claim(ClaimTypes.Name, "name")
                  ,new Claim(ClaimTypes.Email, "email@email.com")
                  ,new Claim(ClaimTypes.Role, "Foo")
              };
              var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
  
              Authentication.SignIn(new AuthenticationProperties() { IsPersistent = true }, identity);
          }
      }
  </code></pre>
  
  <p>If I hit the the login api twice I would have expected the second time that the fooBar variable to be set to a user who is marked as authenticated, but when I check it, it just says it's not authenticated, and it doesn't have any of the claims I would have expected.</p>
  
  <p>I also tried creating a basic service to just check to see if it was authenticated in case I misunderstood how it worked, but this also fails. If I try to go to it, it says I'm not authenticated, it doesn't redirect me as I thought it would.</p>
  
  <pre><code>public class TestController : ApiController
      {
          [Authorize(Roles = "Foo")]
          public int Get()
          {
              return 1;
          }
      }
  </code></pre>
  
  <p>I'm sure I must just be missing some basic, but so far no matter what I fiddled with and regardless of the various guides and advice I've seen online, nothing has been able to get even this simple scenario working. Any ideas on what I'm doing wrong?</p>