title: MVC 5 OWIN login with claims and AntiforgeryToken. Do I miss a ClaimsIdentity provider?
body: <p>I'm trying to learn Claims for MVC 5 OWIN login. I try'ed to keep it as simple as possible. I started with the MVC template and inserted my claims code (see below). I get an error when I use the @Html.AntiForgeryToken() helper in the View.</p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or  
  'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovid    
  er' was not present on the provided ClaimsIdentity. 
  
  To enable anti-forgery token support with claims-based authentication, please verify that 
  the configured claims provider is providing both of these claims on the ClaimsIdentity 
  instances it generates. If the configured claims provider instead uses a different claim 
  type as a unique identifier, it can be configured by setting the static property 
  AntiForgeryConfig.UniqueClaimTypeIdentifier.
  
  Exception Details: System.InvalidOperationException: A claim of type
  'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 
  'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was 
  not present on the provided ClaimsIdentity. To enable anti-forgery token
  support with claims-based authentication, please verify that the configured claims provider 
  is providing both of these claims on the ClaimsIdentity instances it generates. 
  If the configured claims provider instead uses a different claim type as a unique 
  identifier, it can be configured by setting the static property 
  AntiForgeryConfig.UniqueClaimTypeIdentifier.
  
  Source Error:
  Line 4:      using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new 
  { id = "logoutForm", @class = "navbar-right" }))
  Line 5:      {
  Line 6:      @Html.AntiForgeryToken()
  </code></pre>
  
  <p><strong>POST Login action</strong></p>
  
  <pre><code>// POST: /Account/Login
  [HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
  {
      if (!ModelState.IsValid)
      {
          return View(model);
      }
  
      var claims = new List&lt;Claim&gt;
      {
          new Claim(ClaimTypes.Name, "Brock"),
          new Claim(ClaimTypes.Email, "brockallen@gmail.com")
      };
      var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
  
      var ctx = Request.GetOwinContext();
      var authenticationManager = ctx.Authentication;
      authenticationManager.SignIn(id);
  
      return RedirectToAction("Welcome");
  }
  </code></pre>
  
  <p><strong>_LoginPartial.cshtml</strong></p>
  
  <pre><code>@using Microsoft.AspNet.Identity
  @if (Request.IsAuthenticated)
  {
      using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
      {
      @Html.AntiForgeryToken()
  
      &lt;ul class="nav navbar-nav navbar-right"&gt;
          &lt;li&gt;
              @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
          &lt;/li&gt;
          &lt;li&gt;&lt;a href="javascript:document.getElementById('logoutForm').submit()"&gt;Log off&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
      }
  }
  </code></pre>
  
  <p>I have tryed setting <code>ClaimTypes.NameIdentifier</code> (<a href="https://stackoverflow.com/questions/19977833/anti-forgery-token-issue-mvc-5">like in this SO answer</a>)</p>
  
  <pre><code>protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
      BundleConfig.RegisterBundles(BundleTable.Bundles);
  
      AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
  }
  </code></pre>
  
  <p>And then I "only?" get this error</p>
  
  <pre><code>A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' was 
  not present on the provided ClaimsIdentity.
  </code></pre>
  
  <p>I want to keep the antiforgeryToken because it can help against cross-site scripting.</p>